我可以告訴你,這是我長期以來看到的最瘋狂的事情。Linux/Unix腳本 - 幾行中最奇怪的行爲 - 變量集但是爲空
我有這樣的(部分)在CentOS 5.4上運行sh腳本:
# Check GOLD_DIR`
echo $GOLD_DIR"<--"
#export GOLD_DIR=/share/apps/GOLD_Suite/GOLD <uncommenting this line works!!
if [ "X$GOLD_DIR" = "X" ] ; then
echo "ERROR: GOLD_DIR is (probably) not set on host ${HostName}" >> ${3}
exit 1
fi
這給出了以下的輸出:
/share/apps/GOLD_Suite/GOLD<--
Waiting for 5 seconds ..... Testing output
The test script did spawn a job (i.e. PVM ran OK),
but errors were detected in the test script output
on the host machine: Below is the output
ERROR: GOLD_DIR is (probably) not set on host xxx.yyy.local
正如你可以看到GOLD_DIR
變量被設置(在腳本通過後綴爲「<--
」的輸出顯示它)!如果我在腳本代碼(第一個代碼段)中取消註釋GOLD_DIR
變量的導出,則一切正常。
編輯:(使用export GOLD_DIR=/share/apps/GOLD_Suite/GOLD
)
任何想法,爲什麼GOLD_DIR
在/etc/profile
出口?
注1:我不知道這是否重要,但這是PVM上的衍生腳本。
注2:劇本是寫在SH #!/bin/sh
但我使用bash ...
EDIT3:我得到了它的工作,但我不知道爲什麼! - 好吧,我所做的就是將主機名(使用sudo hostname abc
)重命名爲我登錄的計算機的名稱(例如abc)。在PVM列出機器的全名abc.mycompany.local
之前。請注意,abc.mycompany.local
和abc
是同一臺機器。
不,它不起作用。我可以看到變量的內容,如果我在你的語句後立刻進行回顯,但我仍然得到ERROR:...位。 – MalteseUnderdog 2011-02-08 11:06:08