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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix don't want to do 0 + 0, why?

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
$ let somme=0+0
$ echo $?
1
$ let somme=1+0
$ echo $?
0
$let somme=1-1
$ echo $?
1
$ let somme=1-0
$ echo $?
0
$ let somme=1-2
$ echo $?
0
 
The status of the let command is not set to the result of the assignment.
I think that it is set to 1 if result is null (0) and 0 if not.





Jean Pierre.
 
From man ksh, about the let builtin:
The exit status is 0 if the value of the last expression is non-zero, and 1 otherwise.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
bc works fine!

$ echo "0 + 0" | bc
0
$ echo "0 + 1" | bc
1
$ echo "1 + 0" | bc
1
$ echo "1 + 1" | bc
2
$ echo "302332 + 1" | bc
302333
$


Regards
-- Franz
Sorry I'm not a native spaeker, I'm from Munich, Germany - "Home of the Whopper", oh no, "Home of the Oktoberfest" ;-)
Solaris System Manager; I used to work for Sun Microsystems Support (EMEA) for 5 years
 
cantubas, try this:
$ let somme=0+0
$ echo $somme
0
$ let somme=1+0
$ echo $somme
1
$ let somme=1-2
$ echo $somme
-1



Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
I want to know why the status of the command is 1 when I do 'let somme=0+0' and 0 when I do anather additions

i know that $? is not the result of the addition!!!!!!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top