bash - usr - variable path linux
Detectar si el archivo ejecutable está en el PATH del usuario (5)
Aún mejor, puedes usar which :
path_to_executable=$(which name_of_executable)
if [ -x "$path_to_executable" ] ; then
echo "It''s here: $path_to_executable"
fi
En un script de bash, necesito determinar si un ejecutable llamado foo está en el PATH.
También puedes usar el type -P Bash builtin type -P :
help type
cmd=ls
[[ $(type -P "$cmd") ]] && echo "$cmd is in PATH" ||
{ echo "$cmd is NOT in PATH" 1>&2; exit 1; }
Use which
$ which myprogram
si comando -v foo; entonces foo; else echo "foo no disponible"; fi
if [ $(which foo) ]; then
echo foo is in PATH
fi