Tcsh运行命令(如果已运行命令) [英] Tcsh run command if command was run

查看:89
本文介绍了Tcsh运行命令(如果已运行命令)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太熟悉TCSH

如果<$ c,我想运行 command2 在外壳程序中输入了$ c> command1 ,例如:

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

我尝试了此代码,但没有用。第二步是读取文件并将command1更改的某些变量打印在文件中(仅对某些变量具有某种历史记录)。

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

推荐答案

您可以使用$?

#!/bin/tcsh

# command below can fail or succeed
command1

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

这篇关于Tcsh运行命令(如果已运行命令)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆