本文介绍了如何从csh脚本中查找某个命令是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在csh脚本中,仅当有特定命令可用时,我才需要执行某些操作。我想做类似的事情
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
如何在csh或tcsh中执行此操作?
how to do that in csh or tcsh?
推荐答案
我想使用where命令可以解决您的问题
I guess using the where command will solve your issue
检查此:
~/animesh >where grep
/bin/grep
/tools/cfr/bin/grep
~/animesh >where egrep
/bin/egrep
/tools/cfr/bin/egrep
~/animesh >where xgrep
~/animesh >
所以可以说您正在尝试查找名为my_cmd
的命令,请尝试以下代码:
so lets say you are trying to find a command named my_cmdtry the following code:
if(`where my_cmd` != "") then
my_cmd
endif
这篇关于如何从csh脚本中查找某个命令是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!