我正在使用: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