问题
In a csh script, I need to perform something only if a certain command is available. I wanted to do something like
if( _WHAT_TO_PUT_HERE_ ) then # enter only if command "cmd" is in the path
cmd ...
endif
how to do that in csh or tcsh?
回答1:
I guess using the where command will solve your issue
Check this:
~/animesh >where grep
/bin/grep
/tools/cfr/bin/grep
~/animesh >where egrep
/bin/egrep
/tools/cfr/bin/egrep
~/animesh >where xgrep
~/animesh >
so lets say you are trying to find a command named my_cmd try the following code:
if(`where my_cmd` != "") then
my_cmd
endif
来源:https://stackoverflow.com/questions/11137577/how-to-find-from-within-a-csh-script-whether-a-certain-command-is-available