LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem with exit command (https://www.linuxquestions.org/questions/linux-newbie-8/problem-with-exit-command-722436/)

shreyas_1 04-29-2009 04:30 AM

Problem with exit command
 
Hi,

I am executing script written by other user.
I am executing script A.ksh, and A.ksh calls B.ksh.

But It is giving error:
/home/user/B.ksh[132]: exit: -1: unknown option

When I checked B.ksh
It has following lines of code
if [ $success = 0 ]
then
...
some action
...
else
...
some action
...
exit -1
fi


I am new to linux, Can you please help me?

Thank you

ilikejam 04-29-2009 04:55 AM

Hi.

Unix exit status codes have to be in the range 0-255, so -1 is out of range. I'd probably just change it to '1'.

Dave

JulianTosh 04-29-2009 05:01 AM

I agree with Dave. Typically, '-1' is meant to set all bits to 1 to flag a general error condition. Exiting with '255' would be probably be a better direct translation, but unless some other process is checking for a specific return value, anything other than zero would suffice.

linuxlover.chaitanya 04-29-2009 05:42 AM

Something that can help you further.

http://tldp.org/LDP/abs/html/exit-status.html

colucix 04-29-2009 06:45 AM

I agree. However it should not give an error, but it should translate it to 255. The problem is that it interprets the value -1 as an option. Eventually you can try
Code:

exit -- -1
but take in mind that the shell sees the exit code as 255.

barunparichha 04-29-2009 07:08 AM

[$success = 0]
The code always goes to else part and runs " exit -1".

chrism01 04-29-2009 07:29 AM

The above advice is correct.
In a addition, the code you've shown does not set success to anything, so the condition will fail, as it does.
Strictly speaking (as you seem to be doing a numerical comparison), the syntax is
Code:

if [[ $success -eq 0 ]]
then
...

as per http://www.tldp.org/LDP/abs/html/tes...ml#DBLBRACKETS


All times are GMT -5. The time now is 08:43 AM.