开发者

Failing if diff is found (c-shell)

Please resist the urge to tell me not to use c-shell.

I'm writing a c-shell script and I need t开发者_如何学JAVAo run a diff between two files (generated in the script). How do I run diff and return its status (if it fails, return 1, else 0)?


In C shell you can use the variable $status to get the exit status of the command.

% echo 'hi' > foo
% echo 'ho' > bar
% diff foo foo
% echo $status
0
% diff foo bar > /dev/null
% echo $status
1

In a script you can do something like:

set f1=foo
set f2=bar
diff $f1 $f2 > /dev/null                   
if ($status == 0) then
        echo 'no diff'
else
        echo 'diff'
endif
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜