01-14-07 12:20 PM
2007-01-14, 01:42(-08), RolandRB:
> I want to run "cmp" on a batch of files that fits a file pattern but I
> want the return code to be displayed at the end of "cmp" processing. Is
> this possible just using "xargs" as in the example below? I have tried
> "cmp {} txtdir/{} ; echo \$?" but it gives a syntax error.
>
> $ ls -1 r*.txt | xargs -t -I {} cmp {} txtdir/{}
> cmp roland.txt txtdir/roland.txt
> cmp roland2.txt txtdir/roland2.txt
> roland2.txt txtdir/roland2.txt differ: char 1, line 1
> cmp roland3.txt txtdir/roland3.txt
You cmp may have a verbose option.
Otherwise, you'd have to have xargs call sh, so best it to do
the whole thing with the shell:
(
set -x
for f in r*.txt; do
cmp "$f" "txtdir/$f"; echo "$?"
done
)
--
Stéphane
[ Post a follow-up to this message ]
|