Tcsh run command if command was run

家住魔仙堡 提交于 2019-12-31 03:11:49

问题


I'm not really familiar with TCSH

I would like run a command2 if a command1 was entered in the shell, something like this:

if command1  then
    echo "Command succeeded"
    command2
else
    echo "Command failed"
fi

I tried this code but it doesn't work. Step two would be to read and print in a file a part some variable that command1 changed (making a kind of history only for some variables).


回答1:


You can use $? to get exit code from last command.

#!/bin/tcsh

# command below can fail or succeed
command1

if ( $? == 0 ) then
 command2
else
 echo "command1 failed"
endif


来源:https://stackoverflow.com/questions/34457821/tcsh-run-command-if-command-was-run

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