Bash unbound variable array (script: s3- bash)

I work with: s3-bash , when I run it in my local environment ( OS X 10.10.1) I have no problem, when I try to run it on ubuntu server 14.04.1, I get the following error:

./s3-common-functions: line 66: temporaryFiles: unbound variable
./s3-common-functions: line 85: temporaryFiles: unbound variable

I looked at the s3-common-functionsscript and the variable looks properly initialized (like an array):

# Globals
declare -a temporaryFiles

But there is a note in the comment, and I'm sure this is related:

# 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"
}
+4
source share
3 answers

Here, apparently, there is a change in the behavior of bash.

Found kojiro: CHANGES

. ​​, - `declare '` test' ,        , .        .

$ bash --version
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
$ set -u
$ declare -a tF
$ echo "${#tF[@]}"
0

.

$ bash --version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ set -u
$ declare -a tF
$ echo "${#tF[@]}"
0

.

$ bash --version
GNU bash, version 4.3.30(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ set -u
$ declare -a tF
$ echo "${#tF[@]}"
-bash: tF: unbound variable

declare -a tF=() bash, .

$ declare -a tF=()
$ echo "${#tF[@]}"
0
+9

Bash .

set -u
my_array=()
printf "${my_array[@]-}\n"

, .

+2

Modified array declaration for temporaryfiles

declare -a temporaryFiles

at

temporaryFiles=()

Why is this different / not working in ubuntu 14.04.1 Linux 3.13.0-32-generic x86_64versus OS XI'm not sure?

0
source

All Articles