を返さhttp://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.htmlを参照してください。
ステータスの値のみ最下位8ビットが、0、EXIT_SUCCESS、EXIT_FAILURE、[CX]または他の任意の値であってもよい(すなわち、ステータス& 0377)は、待機中の親プロセスに対して利用可能でなければならない。
UNIX終了ステータスは8ビットしかありません。 256オーバーフローので、私はその場合の動作は単純に定義されていないと思います。たとえばこれは、Ruby 1.9.3を搭載したMac OS 10.7.3上で起こる:私のシェルは何を示すかと一致している
irb(main):008:0> `sh -c 'exit 0'`; $?
=> #<Process::Status: pid 64430 exit 0>
irb(main):009:0> `sh -c 'exit 1'`; $?
=> #<Process::Status: pid 64431 exit 1>
irb(main):010:0> `sh -c 'exit 2'`; $?
=> #<Process::Status: pid 64432 exit 2>
irb(main):011:0> `sh -c 'exit 255'`; $?
=> #<Process::Status: pid 64433 exit 255>
irb(main):012:0> `sh -c 'exit 256'`; $?
=> #<Process::Status: pid 64434 exit 0>
は
$ sh -c 'exit 256'; echo $?
0
$ sh -c 'exit 257'; echo $?
1
私はあなたが(もしシェルスクリプトを修正する提案したいです可能な場合)< 256を返します。
出典
2012-04-29 18:04:07
Jan
のRubyのバージョンは何? 1.9.2-p180では、 '$?。exitstatus'はシェルの' $? 'と同じ値を返します。 1.8.7-p334と1.9.3-p0では。どのようなOSですか? –
ええ、私は '#'を取得します。 –
Chuck