Skip to content

Instantly share code, notes, and snippets.

@dschep
Created February 24, 2016 03:43
Show Gist options
  • Select an option

  • Save dschep/3aa5bdc96ceb07fc79da to your computer and use it in GitHub Desktop.

Select an option

Save dschep/3aa5bdc96ceb07fc79da to your computer and use it in GitHub Desktop.
Stupid Macs
#!/bin/bash
#
# Are you tired of making sure your scripts work on a Mac? Source this (or
# copy it!) in your script and use $sed and always be sure it's GNU sed. If
# the GNU tools required aren't installed, it suggest the user install them via
# brew and exits
#
# Default tools: sed & grep
# Override via GNU_TOOLS env variable, ex:
# GNU_TOOLS=sed . gnu-mac.sh
#
GNU_TOOLS=${GNU_TOOLS:-sed grep}
exit=''
for tool in $GNU_TOOLS; do
if [ "$(uname)" == darwin ]; then
if ! type -p g$tool &> /dev/null; then
exit=1
echo "Please install GNU $tool:
brew install gnu-$tool
" 1>&2
else
eval $tool=g$tool
fi
else
eval $tool=$tool
fi
done
[ -z "$exit" ] || exit $exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment