2015-01-20 2 views
4

s3-bash 로컬 환경 (OS X 10.10.1)에서 실행할 때 ubuntu server 14.04.1에서 실행할 때 아무런 문제가 없습니다.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" 
} 
+1

'언 바운드 변수 '는'set -u'를 사용할 때 얻을 수있는 것입니다. 스크립트를 실행하는 환경이 무엇이든간에 설정 했습니까? –

+1

이 오류의 원인이되는 명령은 무엇입니까? –

+2

버그? 댓글 텍스트에 설명 된 내용은 버그가 아니지만 정상적이고 예상되는 동작입니다. 'foo = $ (bar)'는 서브 쉘에서'bar'를 실행하기 때문에 ** 서브 쉘 내부에서 수행되는 ** 할당은 부모 쉘에 전파되지 않습니다. –

답변

9

여기에 배쉬 동작 변경이있는 것 같습니다. 코지로에 의해 발견

: CHANGES

hhhh. Fixed a bug that caused `declare' and `test' to find variables that had been given attributes but not assigned values. Such variables are not set.

$ 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 
당신은 생를 해결하기 위해 새로운 bash는 버전에 declare -a tF=()을 사용할 수 있습니다

에스.

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

bash-4.2-release와 bash-4.3-alpha 사이에서 변경되었습니다. [_hhhh. 속성을 부여 받았지만 값이 할당되지 않은 변수를 찾기 위해 \ 선언 및 \ test를 야기한 버그가 수정되었습니다. 그러한 변수는 설정되지 않습니다. _] (https://tiswww.case.edu/php/chet/bash/CHANGES) - (죄송합니다 txt는 더 정확한 연결을 허용하지 않지만 원하는 경우 정확한 텍스트를 검색 할 수 있습니다. .) – kojiro

+1

@kojiro 그것을 찾아 주셔서 감사합니다. –

0

변경된 선언 :이 OS Xubuntu 14.04.1 Linux 3.13.0-32-generic x86_64 다른/비 기능이 왜

temporaryFiles=() 

나는 확실하지 않다?

2

Bash는 대시를 사용하여 설정되지 않은 변수를 빈 값으로 대체 할 수 있습니다.

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

이 구체적인 예는 아무 것도 인쇄하지 않지만 언 바운드 변수 오류도 표시하지 않습니다.

Stolen from here

+0

크기를 찾으려고 할 때 작동하지 않습니다. 나는. $ {# my_array [@] -} 잘못된 대체 오류가 생성됩니다. – kenj