sh - POSIX way to find the path of foo without `which`? -
i've encountered machine not have which
. how find path executable foo
without which
in posix compliant shell script, if foo
might not present?
the code have following:
- if
which
appears available accordingtype which
exiting 0, use it - otherwise use
type foo
, depending ontype
says (does output contain of following: keyword, builtin, alias, hash, function), grab path according position in output.
the main problem this, @chepner , man page point out, type
stdout in unspecified format.
my other problem foo
might not ever exit, can't execute see happens. want inspect first need know is.
i feel find / -type f -name foo 2>/dev/null
take long. suppose iterate on $path
find directly. which approach best? iterating on $path
or approach in 2 bullets above, or other approach? need solution portable.
Comments
Post a Comment