>> "ueda" == ueda <ueda@xxxxxxxxxxxxxxxxxx> writes:
ueda> 今回問題の発端となったのは、PBS(バッチジョブを投入するシステム) のqsub
ueda> コマンドを使うスクリプトでした。
これがどういうシステムなのかわからないのですが、
ueda> =========================
ueda> for i in 1 2 3 4 5; do
ueda> for j in 1 2 3 4 5; do
ueda> qsub -v i,j 変数iとjを使うバッチスクリプト
ueda> done
ueda> done
ueda> =========================
ueda> qsub は -v 変数名 と書くと環境変数を中のバッチジョブに渡してくれるので
ueda> すが(というかそれ以外に情報を渡す手段がない)、j はちゃんと伝わるのに、
ueda> i だけ伝わらないという非常に分かりにくいバグが出たのです。
どっちかというと中のバッチスクリプトが ~/.bashrc を読む方が
問題ではないかと思います。
/etc/bashrc は ~/.bashrc からしか読まれないものですが、
~/.bashrc
The individual per-interactive-shell startup file
というものなのでスクリプトが読むものではないのではないかと。
ueda> どの変数名が伝わらなくてどの変数が伝わるのか、PBSの問題なのかrshの問題
ueda> なのか、なぜ変数 i なのか、かなり悩みました。
rsh を使ってるんですか?
そうすると次のが関係ありますかねえ。
Bash attempts to determine when it is being run by the
remote shell daemon, usually rshd. If bash determines it
is being run by rshd, it reads and executes commands from
~/.bashrc, if that file exists and is readable. It will
not do this if invoked as sh. The --norc option may be
でも、読むのは rshd から直接起動されたシェルだけのような。
違うかな?
あ、 ~/.bash_profile で
BASH_ENV=$HOME/.bashrc
とされてますね。これだとスクリプトでも読んでしまうか。
この話とは別に、 /etc/profile.d/*.sh は、 /etc/bashrc ではなく
/etc/profile が読むべきだと思っていますが。
# そのように変更してもほぼ問題ないと思います。
まあ、そうしてもバッチスクリプトが /etc/profile.d/*.sh の設定を
必要とするなら同じことなので、解決になりませんね。
# local が function 以外の複合文でも使えたり、
# anonymous function が使えたりしたら、すっきりするのだが…。
# file local な変数というのでもいいな。
--
西村 大介 <nishi@xxxxxxxxxxxxxxxxxxxxx>
東京大学 総合文化研究科 広域システム科学系