Commit 350d5950 authored by Vitaly Lipatov's avatar Vitaly Lipatov

prescription.d/common.sh: simplify print_command_path with is_bash + command -v

parent d1597a87
...@@ -28,23 +28,22 @@ assure_root() ...@@ -28,23 +28,22 @@ assure_root()
} }
# print a path to the command if exists in $PATH # detect bash
if a= type -a type 2>/dev/null >/dev/null ; then is_bash()
print_command_path()
{ {
a= type -fpP -- "$1" 2>/dev/null [ -n "$BASH_VERSION" ]
} }
elif a= which which 2>/dev/null >/dev/null ; then
# the best case if we have which command (other ways needs checking) # print a path to the command if exists in $PATH
# TODO: don't use which at all, it is a binary, not builtin shell command if is_bash ; then
print_command_path() print_command_path()
{ {
a= which -- "$1" 2>/dev/null type -fpP -- "$1" 2>/dev/null
} }
else else
print_command_path() print_command_path()
{ {
a= type "$1" 2>/dev/null | sed -e 's|.* /|/|' command -v "$1" 2>/dev/null
} }
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment