views:

29

answers:

1

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

I'm writing a c-shell script and I need to 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)?

+3  A: 

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
codaddict
This is decent. Does it not as expected for you?
Noufal Ibrahim