Originally Posted by Hobbletoe
catkin is on the right track here. Whenever you use a pipe on the command line, the return code that is returned is not what you expect. You are getting the return code for part of the command, but not the whole line. I think that you answer will be in restructuring your command so that you don't have that pipe in it. Try ...
In bash, the return status of a pipeline is this of the last command, even if some previous part of the pipeline failed
. You can easily test with any meaningless command. For example, this should return non-zero:
stat / | stat /asdf
While this will return 0, because the last command will suceed even if the previous one fails:
stat /asdf | stat /
In a pipe, all commands run regardless if a previous one failed. Never forget that.
However, since bash 3.0 we can do this:
If you do this, the pipe will return the last non-zero exist status. Hence, the result of the last command in the pipe that failed. Again, regardless of the result, all the commands in the pipeline will run, which might not be the intended result.
rm $(cat file.list)
Yes, you could do this, but this is not a proper solution. If the list of files is too long it will fail. If you absolutely need something like this, better use xargs, find -exec or a loop like this:
cat file.list | while read file; do whatever with $file; done
Or something similar.