我正在使用:s3-bash,當我在本地環境中運行它時(OS X 10.10.1
)我沒有任何問題,當我嘗試在ubuntu server 14.04.1
上運行它時出現以下錯誤:Bash unbound variable array(script:s3-bash)
./s3-common-functions: line 66: temporaryFiles: unbound variable
./s3-common-functions: line 85: temporaryFiles: unbound variable
我已經看過了s3-common-functions
腳本和變量看起來是正確初始化(作爲數組):
# Globals
declare -a temporaryFiles
但有記下評論,我相信它是否相關:
陣列爲temporaryfiles
declare -a temporaryFiles
到
# Do not use this from directly. Due to a bug in bash, array assignments do not work when the function is used with command substitution
function createTemporaryFile
{
local temporaryFile="$(mktemp "$temporaryDirectory/$$.$1.XXXXXXXX")" || printErrorHelpAndExit "Environment Error: Could not create a temporary file. Please check you /tmp folder permissions allow files and folders to be created and disc space." $invalidEnvironmentExitCode
local length="${#temporaryFiles[@]}"
temporaryFiles[$length]="$temporaryFile"
}
'unbound variable'是你在使用'set -u'的時候得到的。您是否在任何環境下設置了該腳本? – 2015-01-20 21:23:28
導致此錯誤的命令是什麼? – 2015-01-20 21:28:56
錯誤?評論文字中描述的內容不是一個錯誤,而是正常和預期的行爲。 'foo = $(bar)'在子shell中運行'bar',所以當然在那個子shell中完成的**賦值不會傳播到父shell。 – 2015-01-20 22:19:34