我正试着写一个tcsh脚本。如果任何命令失败,我需要脚本退出。
在shell中,我使用set -e,但在tcsh中不知道它的等价性
#!/usr/bin/env tcsh
set NAME=aaaa
set VERSION=6.1
#set -e equivalent
#do somthing谢谢
发布于 2015-08-18 13:34:45
在(t)csh中,set用于定义变量;set foo = bar将将值bar分配给变量foo (就像伯恩shell脚本中的foo=bar一样)。
无论如何,来自tcsh(1)
Argument list processing
If the first argument (argument 0) to the shell is `-' then it is a
login shell. A login shell can be also specified by invoking the shell
with the -l flag as the only argument.
The rest of the flag arguments are interpreted as follows:
[...]
-e The shell exits if any invoked command terminates abnormally or
yields a non-zero exit status.因此,您需要使用tcsh标志调用-e。让我们来测试一下:
% cat test.csh
true
false
echo ":-)"
% tcsh test.csh
:-)
% tcsh -e test.csh
Exit 1无法像sh的set -e那样在运行时设置它,但是您可以将它添加到hashbang中:
#!/bin/tcsh -fe
false因此,当您运行./test.csh时,它会自动添加,但是当您键入csh test.csh时,这将是而不是添加它,所以我的建议是使用类似于调用csh脚本的start.sh:
#!/bin/sh
tcsh -ef realscript.cshhttps://stackoverflow.com/questions/32069885
复制相似问题