LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
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
 
Old 04-29-2009, 04:55 AM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
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
 
Old 04-29-2009, 05:01 AM   #3
JulianTosh
Member
 
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, 05:42 AM   #4
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Gurgaon, India
Distribution: Cent OS 6/7
Posts: 4,631

Rep: Reputation: Disabled
Something that can help you further.

http://tldp.org/LDP/abs/html/exit-status.html
 
Old 04-29-2009, 06:45 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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.
 
Old 04-29-2009, 07:08 AM   #6
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
[$success = 0]
The code always goes to else part and runs " exit -1".
 
Old 04-29-2009, 07:29 AM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
  


Reply


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 7 03-31-2018 10:29 AM
How to exit and save (or just to exit) inside a "make config" running command? scrat75 Linux - Kernel 6 09-05-2008 04:02 PM
Warning: at kernel/exit.c:814 do exit() (Tainted: P ) <- nVidia video problem? Hitboxx Fedora 2 10-06-2007 09:47 PM
How to exit from > in command prompt ? FinnGnome Linux - Newbie 6 05-09-2003 02:50 PM
script 'exit' command kilobravo Linux - General 8 01-16-2003 03:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:29 PM.

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