LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-28-2014, 04:22 AM   #1
massy
Member
 
Registered: Nov 2013
Distribution: CentOS 6.4
Posts: 209
Blog Entries: 1

Rep: Reputation: Disabled
Exit command


what happens if I don't put exit in a shell script?
and what happens if I put exit 10000 in the end of a shell script?
I did it, and after running the script, It showed an error: too many argument, and added some 10000 in the end of the file of shell script code!?why?
 
Old 01-28-2014, 04:38 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
I'm assuming you use a bash shell:

Quote:
Originally Posted by massy View Post
what happens if I don't put exit in a shell script?
The the script returns the exit status of the last command executed in the script.

In general: An exit status of 0 (zero) tells you that all is OK. Any other status might indicate that something is wrong.

There are exceptions, the grep command being one. 0 means found, 1 means not found and 2 or larger means an actual error. Do check the manual page of the command to see which exit statuses can be generated.

Quote:
and what happens if I put exit 10000 in the end of a shell script?
10000 is an illegal number.
An exit status can be anything from 0 (zero) to 255. If you use a larger number bash will reduce it to the 0-255 range. In other words: exit 256 will return 0, exit 769 returns 1

Quote:
I did it, and after running the script, It showed an error: too many argument, and added some 10000 in the end of the file of shell script code!?why?
Not sure if this related to the exit command. I do not get an error when using exit 10000

BTW: You can check the exit status by running: echo $?

All the ins and outs regarding exit can be found in the bash manual page (the EXIT STATUS section).
 
1 members found this post helpful.
Old 01-28-2014, 05:14 AM   #3
massy
Member
 
Registered: Nov 2013
Distribution: CentOS 6.4
Posts: 209

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
I'm assuming you use a bash shell:

The the script returns the exit status of the last command executed in the script.

In general: An exit status of 0 (zero) tells you that all is OK. Any other status might indicate that something is wrong.

There are exceptions, the grep command being one. 0 means found, 1 means not found and 2 or larger means an actual error. Do check the manual page of the command to see which exit statuses can be generated.

10000 is an illegal number.
An exit status can be anything from 0 (zero) to 255. If you use a larger number bash will reduce it to the 0-255 range. In other words: exit 256 will return 0, exit 769 returns 1

Not sure if this related to the exit command. I do not get an error when using exit 10000

BTW: You can check the exit status by running: echo $?

All the ins and outs regarding exit can be found in the bash manual page (the EXIT STATUS section).
You're right; thank you
 
  


Reply



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 On
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
system command ; how to exit? kewl Linux - Software 1 07-08-2009 02:04 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
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 - General

All times are GMT -5. The time now is 11:20 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