LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-10-2018, 09:16 AM   #1
cuintilo
LQ Newbie
 
Registered: Jun 2018
Distribution: Debian stretch
Posts: 14

Rep: Reputation: 0
Use of exit status variables (for example, E_NOARGS) clarification needed


Hello

I've been reading abs-guide after researching some man pages and doing some simple scripts and while after beginning I feel I understand majority of information presented I didn't manage to wrap my thoughts around concept of variables used in examples there.

For example, if you have an exception handler (is it called like this?) which informs that input should contain something and which ends with line

Quote:
exit $E_NOARGS
What does that variable actually do? It's been given value of 65 in the example script, but why that value? Is it just some convention used for this type of exit, since status should still be 'false', yes? I read exit function man page, but it didn't state anything about this matter. Help reaching clarity on the matter is greatly appreciated.
 
Old 07-10-2018, 09:21 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> What does that variable actually do?

The variable does nothing, only holds a value.

> It's been given value of 65 in the example script, but why that value?

Because the programmer choose that value. Actually, it could be anything but zero.

> Is it just some convention used for this type of exit, since status should still be 'false', yes?

Nonzero is a more precise term. Zero=Success, Non-zero=Failure
 
1 members found this post helpful.
Old 07-10-2018, 10:57 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
It is information to the caller if it failed or not.
0 is success, > 0 is a clue to the error, maybe 1 is 'not found' 2 is 'not allowed' etc.

In linux it is a mash up of the status and the signal in the exit code.
I set my prompt to show the exit code of the last command:

Code:
$ PS1='$? $ '
0 $ cat flap
cat: flap: No such file or directory
1 $ (exit 99)
99 $ (exit 255)
255 $ (exit 256)
0 $
 
  


Reply

Tags
bash



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
dhclient-exit-hooks.d/rfc3442-classless-routes returned non-zero exit status Shr0912 Debian 2 01-17-2018 02:40 PM
exit status for system call (exit) Tala_22 Linux - Kernel 2 10-20-2015 06:51 PM
Clarification setting environmental Variables JAVA_Home and JDK_HOME econ8193 Linux - Newbie 1 09-25-2012 07:16 AM
Clarification Needed nagu_linux Linux - Software 1 03-30-2005 02:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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