Skip to content

Instantly share code, notes, and snippets.

@tlatsas
Created September 12, 2013 12:46
Show Gist options
  • Save tlatsas/6536715 to your computer and use it in GitHub Desktop.
Save tlatsas/6536715 to your computer and use it in GitHub Desktop.
return the location of a binary by searching in $PATH
#!/bin/bash
[[ -z $1 ]] && { echo "usage: inpath <filename>"; exit 1; }
for path in ${PATH//:/ }; do
if [[ -e "$path/$1" ]]; then
echo "$path/$1" && exit 0
fi
done
echo "$1 not in \$PATH" && exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment