Created
March 7, 2016 13:44
-
-
Save caruccio/7626f96fb2d14389af73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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