开发者

Failing if diff is found (c-shell)

开发者 https://www.devze.com 2023-01-20 14:11 出处:网络
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

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

精彩评论

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

关注公众号