Does anyone know how to trap errors from within piped commands in KSH???
example:
ls -l /non-existent-dir | ls -l /existing-dir
echo $?
I want to find out if the first command failed or if the second one failed.
I tried:
ls -l /non-existent-dir 2> err.file | ls -l /existing-dir 2>> err.file
if [ -s err.file ]
then
echo "ERROR: `cat err.file`"
exit 1
fi
I think this is rather ugly.
Thanks,
Rudy