harry’s memorandum

おれおれメモ

CentOS6.2のtcshはいまいち

Centos6.2 の tcsh 仕様変更だそうです。*1

Technical Notes:
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.

https://bugzilla.redhat.com/show_bug.cgi?id=658190

パイプ時やバッククォートのコマンドのステータス処理に変更があったと。

$ 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

*1:tcsh-6.17-14.el6.x86_64