Skip to content

Instantly share code, notes, and snippets.

@caruccio
Created March 7, 2016 13:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caruccio/7626f96fb2d14389af73 to your computer and use it in GitHub Desktop.
Save caruccio/7626f96fb2d14389af73 to your computer and use it in GitHub Desktop.
# Returns true (0) if $1 is on $PATH, false (1) otherwise
# Handles path expansions as expected
# Example: is_dir_on_path ~/bin
is_dir_on_path()
{
local path
local dir
# convert $PATH to array
IFS=':' read -r -a path <<<$PATH
for dir in ${path[@]}; do
eval dir=${dir} #expands ~
[ "${dir}" == "${1}" ] && return 0
done
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment