2014-02-26 49 views
1

我想有这样的事情CSH脚本:检查是否存在命令

如果(command_not_exists)出口

谁能告诉我如何实现在此功能cshell脚本?

+0

欢迎StackOverflow上。在其他语言有一个功能尝试这样做,也许在csh中有类似的东西... – Llopis

+1

我的问题是解决使用[链接]解决方案(http://stackoverflow.com/questions/11137577/how-to -find-from-within-a-csh-script-a-certain-command-is-available?rq = 1):if('where test_cmd' ==“”)then echo“test_cmd:Command not found” ;出口(1); endif谢谢@Llopis – BluVio

+0

如果解决了,那么回答你自己的问题并接受它来解决问题。所以其他人知道如何去做,并且阻止其他人为这个问题搜索解决方案:D – Llopis

回答

2

我的问题解决了使用where命令(我试图与which命令)。解决方案:

if(`where test_cmd` == "") then 
     printf "\ntest_cmd: Command not found\n"; 
     exit(1); 
    endif 

感谢

+0

如果'tcsh'是shell并且设置了变量'printexitvalue',它就不起作用,因为'where test_cmd'的计算结果为'如果test_cmd不存在,则退出1。即在shell脚本中,您首先要取消设置'printexitvalue'。 – holger