我將部分shell腳本提取到另一個shell腳本中,出於某種原因,在調用子腳本後,命令替換停止工作。我無法想象這是子腳本中的內容,但我也看不出我做錯了什麼。命令替換中斷命令替換
我是否做:
dirname "$0" # works
echo "`dirname "$0"`" # works
echo "$(dirname "$0")" # works
cat <<< "`dirname "$0"`" # works
cat <<< "$(dirname "$0")" # works
"$(dirname "$0")"/setup_buildroot.sh "$BUILDROOT" # call the sub-script
dirname "$0" # works
echo "`dirname "$0"`" # empty string
echo "$(dirname "$0")" # empty string
cat <<< "`dirname "$0"`" # crash
cat <<< "$(dirname "$0")" # crash
或我做的:
dirname "$0" # works
echo "`dirname "$0"`" # works
echo "$(dirname "$0")" # works
cat <<< "`dirname "$0"`" # works
cat <<< "$(dirname "$0")" # works
"`dirname "$0"`"/setup_buildroot.sh "$BUILDROOT" # call the sub-script
dirname "$0" # works
echo "`dirname "$0"`" # empty string
echo "$(dirname "$0")" # empty string
cat <<< "`dirname "$0"`" # crash
cat <<< "$(dirname "$0")" # crash
目錄名稱似乎工作正常,但反引號和$()
停止工作。命令替換隻是返回一個空字符串。
編輯:刪除所有雙引號""
沒有效果
EDIT2:調用子腳本時明確執行bash有沒有效果
EDIT3:保存"$(dirname "$0")"
一個變量,並且使用有沒有效果
EDIT4:添加相同echo
命令給子腳本顯示,一切正常的子腳本
EDIT5:按熱曲est,腳本輸出
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
/home/jayen/rep
#setup_buildroot.sh output here
/home/jayen/rep
bash: syntax error near unexpected token `newline'
bash: syntax error near unexpected token `newline'
是否正常工作,如果你只是註釋掉行調用標?只是想確定。 – anishsane
你能否提供一些有關下標的細節? – anishsane
此外,嘗試將腳本移動到不包含特殊字符(如空格)的目錄中。你確定,下標正在結束並將控制返回給父腳本嗎? – anishsane