Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo $? returning 13432 in bash on linux

Status
Not open for further replies.

Scunningham99

Programmer
Sep 20, 2001
815
GB
After running a simple script which does a simple echo command. Intermit. getting weird number when expecting 0

ie

echo $?
13264 <-- this number not always the same random??

then Occasionally get a 0. Any ideas?

When we put shell back to ksh we dont get this?

Sy UK
 
Did you run another command before the "[tt]echo $?[/tt]"? If that command had a non-zero return code, it would display that.

 
Hi

SamBones, that not happens to me :
Code:
[blue]master #[/blue] ( exit 13264; )
[blue]master #[/blue] echo $?
208
And as I understand, it neither should.
ABS said:
Within a script, an exit nnn command may be used to deliver an nnn exit status to the shell (nnn must be a decimal number in the 0 - 255 range).
( Advanced Bash-Scripting Guide | Exit and Exit Status )
GNU libc said:
[gray](...)[/gray] the status value is truncated to eight bits. Thus, if the program tried to report 256 errors, the parent would receive a report of 0 errors—that is, success.
( The GNU C Library | The Basic Program/System Interface | Program Termination | Exit Status )


Feherke.
 
That doesn't explain why Scunningham99 is getting seemingly random values that are over 255.

 
Hi

Right. I just tried to point out that answering your "Did you run another command before" question would not lead to the root of problem.


Feherke.
 
So, the whole script is only the echo command ?
If this is the case then I'd insert a dummy command:
Code:
true
echo $?
Otherwise, please post the code

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yeah, time to see some code. Also, could you post the output of these commands?
Code:
bash --version
uname -a

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top