LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   this script's returned value is 120,why?? (https://www.linuxquestions.org/questions/linux-newbie-8/this-scripts-returned-value-is-120-why-4175495918/)

mirage1993 02-23-2014 02:34 AM

this script's returned value is 120,why??
 
I creat a file and edit it .

Code:

#!/bin/bash

exit 888

then,
Code:

[root@localhost]# ./script.sh
[root@localhost]# echo $?
120

I want to know why the returned value is not 888,thanks.

Doc CPU 02-23-2014 03:47 AM

Hi there,

Quote:

Originally Posted by mirage1993 (Post 5123101)
I creat a file and edit it .

Code:

#!/bin/bash

exit 888

then,
Code:

[root@localhost scripts]# ./script.sh
[root@localhost scripts]# echo $?
120

I want to know why the returned value is not 888,thanks.

that's because return values are limited to 8 bits for historical reasons. So the given return value of 888 is truncated, the high-order bits are dropped:

Code:

  888 (dec) = 0x0378
 strip high byte and convert back:
  0x78 = 120 (dec)

There you go.

[X] Doc CPU

mirage1993 02-23-2014 03:53 AM

Quote:

Originally Posted by Doc CPU (Post 5123122)
Code:

  888 (dec) = 0x0378
 strip high byte and convert back:
  0x78 = 120 (dec)



great!!!thank you sooo much!!
@Doc CPU


All times are GMT -5. The time now is 12:46 AM.