I have a shell script that runs a bunch of commands (on OS X 10.7) as part of a build step for XCode. The script removes a bunch of files and copies a bunch of files.
The problem I have right now is that if the cp command fails, the build still ‘succeeds’ according to XCode, presumably because the script still returns with an exit status of 0. How can I capture the result of the cp ? I looked up the man page and it doesn’t seem to return a value.
cpwill return an error code (non zero) on failure, but your script probably ignores it and proceeds to the next command.Unless you explicitly check the return code of each command in a multi-step script, then the shell will carry on.
See Aborting a shell script if any command returns a non-zero value? for how to exit a script on any error.