Skip to content

Instantly share code, notes, and snippets.

@jrnewell
Last active May 20, 2025 16:49
Show Gist options
  • Save jrnewell/26cc1963ed997000a134 to your computer and use it in GitHub Desktop.
Save jrnewell/26cc1963ed997000a134 to your computer and use it in GitHub Desktop.
A windows git-bash script to use a newer version of grep, egrep, fgrep in git-bash.
#!/bin/bash
set -e
set -o pipefail
cd $TEMP
archives=(
'grep-2.5.4-2-msys-1.0.13-bin.tar.lzma'
'libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma'
'libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma'
)
files=(
'grep.exe'
'egrep.exe'
'fgrep.exe'
'msys-iconv-2.dll'
'msys-intl-8.dll'
)
URL="http://downloads.sourceforge.net/sourceforge/mingw"
SEVEN_ZIP="/c/Program Files/7-Zip/7z"
GIT_HOME="/c/Program Files (x86)/Git"
exit_on_error() {
if [ $1 -ne 0 ]; then
echo "error detected, exiting..."
exit 1
fi
}
for archive in ${archives[*]}; do
echo "Downloading $archive"
curl -L -O "$URL/$archive"
exit_on_error $?
echo "Extracting Files using 7-Zip"
tar_archive=`basename $archive .lzma`
"$SEVEN_ZIP" x -y "$archive"
"$SEVEN_ZIP" x -y -ogrep "$tar_archive"
echo "Removing archives"
rm -f "$archive"
rm -f "$tar_archive"
done
echo "Copying Files to $GIT_HOME"
cd "$GIT_HOME/bin"
rm -f egrep
ls -l "$TEMP"/grep/bin/*
mv -f "$TEMP"/grep/bin/* .
echo "Resetting file permissions"
for file in ${files[*]}; do
icacls "$file" //reset
done
rm -rf "$TEMP/grep"
echo "Done!"
exit 0
@octoshrimpy
Copy link

updated:

#!/bin/bash

set -e
set -o pipefail

cd "$TEMP"

archives=(
	'grep-2.5.4-2-msys-1.0.13-bin.tar.lzma'
	'libiconv-1.14-1-msys-1.0.17-dll-2.tar.lzma'
	'libintl-0.18.1.1-1-msys-1.0.17-dll-8.tar.lzma'
)

files=(
	'grep.exe'
	'egrep.exe'
	'fgrep.exe'
	'msys-iconv-2.dll'
	'msys-intl-8.dll'
)

URL="http://downloads.sourceforge.net/sourceforge/mingw"
SEVEN_ZIP="/c/Program Files/7-Zip/7z"
GIT_HOME="/c/Program Files (x86)/Git"

exit_on_error() {
	if [ "$1" -ne 0 ]; then
		echo "error detected, exiting..."
			exit 1
	fi
}

for archive in "${archives[@]}"; do
	echo "Downloading $archive"
	curl -L -O "$URL/$archive"
	exit_on_error $?

	echo "Extracting Files using 7-Zip"
	tar_archive=$(basename "$archive" .lzma)
	"$SEVEN_ZIP" x -y "$archive"
	"$SEVEN_ZIP" x -y -ogrep "$tar_archive"

	echo "Removing archives"
	rm -f "$archive"
	rm -f "$tar_archive"
done

echo "Copying Files to $GIT_HOME"
cd "$GIT_HOME/bin"
rm -f egrep
ls -l "$TEMP"/grep/bin/*
mv -f "$TEMP"/grep/bin/* .

echo "Resetting file permissions"
for file in "${files[@]}"; do
	icacls "$file" //reset
done

rm -rf "$TEMP/grep"

echo "Done!"

exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment