Re: Bug#291026: Executing a command, if present, without 'command not found' message, if not present
Tollef Fog Heen wrote:
> If it's bash-only, wouldn't using bash + command -v be easier? :)
It would be easier, but it would also have the disadvantage that
command -v sometimes prints strings that are not executable commands
(#291197). This means that if the administrator does chmod ugo-x
on a program thinking that this will disable it, command -v will
still report the same path for the program and the attempt to run
it will fail. Ideally our code would avoid this, although I admit
that this is a relatively minor issue.
Earlier in #291026 I showed how to fix up command -v by doing further
testing on its output. The code I gave was even POSIXly correct (but
complex). However, now I am looking for something that implements:
Try command #1 and if it didn't run because the command
was not found, try command #2
rather than implementing:
If command #1 looks runnable then try command #1,
otherwise run command #2
--
Thomas
Reply to: