我瀏覽了解釋全域變數的 shell 腳本教學 ( export
)。我遇到了一個 DIY 範例來說明 shell 腳本中全域變數的概念,我嘗試了以下方法:
$ cat trial
vech=Bus
echo $vech
/bin/bash
echo "before empty line"
echo $vech
echo "after empty line"
vech=Car
echo $vech
exit
echo $vech
該計劃的預期輸出為:
Bus
before empty line
after empty line
Car
Bus
但我得到了:
$ chmod 777 trial
$ ./trial
Bus
$
我哪裡錯了? ,我是新口味,請幫幫我。
答案1
嘗試使用此處文件:
vech=Bus
echo $vech
/bin/bash<<EOF
echo "before empty line"
echo $vech
echo "after empty line"
vech=Car
echo $vech
exit
EOF
echo $vech