0

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.

Ahmad
  • 315
  • 3
  • 16
  • Can you paste the contents of your script into the question? – C. K. Young Nov 15 '12 at 14:04
  • According to [the Apple manpage](http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/cp.1.html) cp returns the success state of the operation, so maybe there's a problem in your script - or a mismatch between cp's definition of success/failure and yours? – fvu Nov 15 '12 at 14:05

1 Answers1

3

cp will 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.

Community
  • 1
  • 1
Rich
  • 15,048
  • 2
  • 66
  • 119
  • apologies for not accepting the answer until now but it simply slipped my mind. Thanks for your help. – Ahmad Jan 14 '13 at 14:58