Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-29-2009, 05:30 AM   #1
LQ Newbie
Registered: Apr 2009
Posts: 1

Rep: Reputation: 0
Problem with exit command


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 ]
some action
some action
exit -1

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

Thank you
Old 04-29-2009, 05:55 AM   #2
Senior Member
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 96

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'.

Old 04-29-2009, 06:01 AM   #3
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
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.
Old 04-29-2009, 06:42 AM   #4
Senior Member
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
Something that can help you further.
Old 04-29-2009, 07:45 AM   #5
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
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
exit -- -1
but take in mind that the shell sees the exit code as 255.
Old 04-29-2009, 08:08 AM   #6
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 285

Rep: Reputation: 32
[$success = 0]
The code always goes to else part and runs " exit -1".
Old 04-29-2009, 08:29 AM   #7
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
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
if [[ $success -eq 0 ]]
as per


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exit the less textfile command? dubbuk Linux - Newbie 6 07-20-2017 09:27 PM
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 05:02 PM
Warning: at kernel/exit.c:814 do exit() (Tainted: P ) <- nVidia video problem? Hitboxx Fedora 2 10-06-2007 10:47 PM
How to exit from > in command prompt ? FinnGnome Linux - Newbie 6 05-09-2003 03:50 PM
script 'exit' command kilobravo Linux - General 8 01-16-2003 04:24 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:47 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration