How to find from within a csh script whether a certain command is available?

孤者浪人 提交于 2019-12-11 14:19:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!