3

How to return from shell script with return value 1 with successful completion of script?

2
  • 4
    What shell environment are you using? If it's bash you'd exit 1?
    – Alistair
    Feb 6, 2011 at 10:06
  • 2
    Don't you think it might be a start to tell what shell?
    – Nanne
    Feb 6, 2011 at 10:06

2 Answers 2

12

Firstly, returning a value of 1 to indicate success is exactly the opposite of expected behavior, so you really should not do it. However, if you want to, then just do

exit 1

However, this typically indicates failure, and you would do well to respect the convention.

2

0 indicates success, non-zero indicates failure. You should use exit or exit 0 in case of success. In case of failure, use exit 1. If you want to return information why your program has failed, you can use several different return values, i. e. 1, 2, 3, -1, 255, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.