CentOS6.2のtcshはいまいち
Technical Notes:
https://bugzilla.redhat.com/show_bug.cgi?id=658190
This package fixes the return value of the "status" (or"$?") variable in the case of pipelines and backquoted
commands. The "anyerror" variable, which selects thebehavior, has been added to retain backward compatibility.
パイプ時やバッククォートのコマンドのステータス処理に変更があったと。
$ cat no-exist | wc -l cat: no-exist: No such file or directory 0 $ echo $? 0 $ set anyerror $ cat no-exist | wc -l cat: no-exist: No such file or directory 0 $ echo $? 1
最後のコマンドは成功しているのだからステータスは 0 を返すべきだ、ということですか。保険で下位互換の set anyerror を設定すれば昔の振る舞いをするんだね。
$ unset anyerror $ set stdout=`cat no-exist` cat: no-exist: No such file or directory $ echo $? 0
でも、これが正常になるのはなんでだろう?
$ which set set: shell built-in command.
setがコマンド(ビルトイン)だから、変数に代入したらコマンド成功!ということで、ステータスは 0 を返すってことにしておこう。
追記(2012-05-28)
元に戻ったらしい。
挙動を変える変数をanyerrorからtcsh_posix_statusに変えたらしい。シェル変数?なのかな。anyerrorの時もそうだけど環境変数にしないと意味なくね。
Previously, the "anyerror" variable could be selected to set the tcsh exit value behavior. However, "anyerror" is a shell variable and therefore was not propagated to subshells, and could not globally affect csh scripts. This update modifies the tcsh exit value behavior to the default behavior of csh: the new "tcsh_posix_status" variable is now available instead of "anyerror" to allow behavior similar to the POSIX standard.
https://bugzilla.redhat.com/show_bug.cgi?id=784510