Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

shell

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

like image 487
Ashitosh Avatar asked Sep 07 '25 13:09

Ashitosh


2 Answers

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.

like image 81
William Pursell Avatar answered Sep 12 '25 05:09

William Pursell


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.

like image 24
Anonymous Avatar answered Sep 12 '25 04:09

Anonymous