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).
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