commit bash-20141128 snapshot

This commit is contained in:
Chet Ramey
2014-12-02 16:15:47 -05:00
parent 0a233f3ec4
commit 09f70f2f67
59 changed files with 54337 additions and 2021 deletions
+3 -3
View File
@@ -16,9 +16,9 @@
9
16
./appendop.tests: line 84: x: readonly variable
declare -A foo='([one]="bar" [two]="baz" [three]="quux" )'
declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
declare -A foo='([two]="baz" [three]="quux" [one]="bar" )'
declare -A foo='([two]="baz" [0]="zero" [three]="quux" [one]="bar" )'
declare -A foo='([two]="baz" [0]="zero" [three]="quux" [four]="four" [one]="bar" )'
declare -ai iarr='([0]="3" [1]="2" [2]="3")'
declare -ai iarr='([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")'
25 25
+3 -3
View File
@@ -351,8 +351,8 @@ version[agent]
version.agent
version[agent] foo[bar]
version.agent bowl
foobar] foo foo[bar]
bleh bbb bleh
foo foobar] foo[bar]
bbb bleh bleh
ab]
bar
1
@@ -371,7 +371,7 @@ declare -a x='([0]="0" [1]="1" [2]="2" [4]="4")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="five")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5foo")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="foo")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4" [5]="5")'
declare -a x='([0]="0" [1]="1" [2]="2" [3]="3" [4]="4four" [5]="5")'
strlen(4four) = 5
+15 -15
View File
@@ -12,7 +12,7 @@ declare -A BASH_ALIASES='()'
declare -A BASH_CMDS='()'
declare -Ai chaff='([one]="10" [zero]="5" )'
declare -Ar waste='([version]="4.0-devel" [source]="./assoc.tests" [lineno]="28" [pid]="42134" )'
declare -A wheat='([one]="a" [zero]="0" [two]="b" [three]="c" )'
declare -A wheat='([two]="b" [three]="c" [one]="a" [zero]="0" )'
declare -A chaff='([one]="10" ["hello world"]="flip" [zero]="5" )'
./assoc.tests: line 38: unset: waste: cannot unset: readonly variable
./assoc.tests: line 39: chaff[*]: bad array subscript
@@ -47,16 +47,16 @@ argv[3] = <blat>
argv[1] = <qux qix blat>
argv[1] = <16>
argv[1] = <16>
argv[1] = <flix>
argv[2] = <6>
argv[1] = <6>
argv[2] = <flix>
argv[1] = <six>
argv[2] = <foo>
argv[3] = <bar>
argv[1] = <six>
argv[2] = <foo bar>
8
/usr/local/bin . /bin /sbin /usr/sbin /usr/bin /bin /usr/ucb
bin . bin sbin sbin bin bin ucb
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
bin
/ / / / / / /
/
@@ -65,16 +65,16 @@ argv[1] = </>
argv[1] = <sbin>
argv[1] = </>
8
/usr/local/bin . /bin /sbin /usr/sbin /usr/bin /bin /usr/ucb
bin . bin sbin sbin bin bin ucb
. /sbin /usr/bin /bin /usr/ucb /usr/local/bin /bin /usr/sbin
. sbin bin bin ucb bin bin sbin
/ / / / / / /
8
4 -- /bin
^usr^local^bin . ^bin ^sbin ^usr^sbin ^usr^bin ^bin ^usr^ucb
^usr^local^bin . ^bin ^sbin ^usr^sbin ^usr^bin ^bin ^usr^ucb
\usr/local/bin . \bin \sbin \usr/sbin \usr/bin \bin \usr/ucb
\usr\local\bin . \bin \sbin \usr\sbin \usr\bin \bin \usr\ucb
\usr\local\bin . \bin \sbin \usr\sbin \usr\bin \bin \usr\ucb
. ^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin ^bin ^usr^sbin
. ^sbin ^usr^bin ^bin ^usr^ucb ^usr^local^bin ^bin ^usr^sbin
. \sbin \usr/bin \bin \usr/ucb \usr/local/bin \bin \usr/sbin
. \sbin \usr\bin \bin \usr\ucb \usr\local\bin \bin \usr\sbin
. \sbin \usr\bin \bin \usr\ucb \usr\local\bin \bin \usr\sbin
([a]=1)
qux foo
@@ -137,11 +137,11 @@ abc
def
def
./assoc5.sub: line 13: declare: `myarray[foo[bar]=bleh': not a valid identifier
abc def bleh
myarray=(["a]a"]="abc" ["]"]="def" ["a]=test1;#a"]="123" [foo]="bleh" )
bleh abc def
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["]"]="def" )
123
myarray=(["a]a"]="abc" ["a]=test2;#a"]="def" ["]"]="def" ["a]=test1;#a"]="123" [foo]="bleh" )
myarray=(["a]=test1;#a"]="123" [foo]="bleh" ["a]a"]="abc" ["a]=test2;#a"]="def" ["]"]="def" )
bar"bie
doll
declare -A foo='(["bar\"bie"]="doll" )'
+1 -1
View File
@@ -163,7 +163,7 @@ declare -A d
declare -a c='([0]="4")'
declare -A c='([0]="4" )'
declare -a c='([0]="1" [1]="2" [2]="3")'
declare -A c='([one]="1" [two]="2" [three]="3" )'
declare -A c='([two]="2" [three]="3" [one]="1" )'
declare -a c='([0]="1" [1]="2" [2]="3")'
declare -a c='([0]="1" [1]="2" [2]="3")'
unset
+33 -1
View File
@@ -570,6 +570,38 @@ c Value = 10 20 40 80
c Sub = 0 2 4 8
<1> <2> <3> <4> <5>
<10> <20> <40> <80>
<>
<>
<>
<>
<'ab '\''cd'\'' ef'>
./new-exp10.sub: line 11: ${x@C}: bad substitution
<'ab'> <'cd ef'> <''> <'gh'>
<'ab' 'cd ef' '' 'gh'>
<'ab'> <'cd> <ef'> <''> <'gh'>
<'ab'> <'cd> <ef'> <''> <'gh'>
<'ab cd'>
<'4'> <'ab cd'>
<>
argv[1] = <host(2)[4.3]$ >
<
>
<' \t\n'>
<
>
<$' \t\n'>
declare -r x='ab '\''cd'\'' ef'
set -- 'ab' 'cd ef' '' 'gh'
declare -a A=([0]="ab" [1]="cd ef" [2]="" [3]="gh")
declare -a B=()
declare -A A=([two]="b c" [three]="" [four]="de" [one]="1" )
r
a
A
ir
a b c d e
5
a5b
argv[1] = </>
argv[1] = </>
./new-exp.tests: line 584: ABXD: parameter unset
./new-exp.tests: line 587: ABXD: parameter unset
+3
View File
@@ -573,6 +573,9 @@ ${THIS_SH} ./new-exp8.sub
# value is 'anothervar[@]' stop working
${THIS_SH} ./new-exp9.sub
# new parameter transformation `@' expansion operator
${THIS_SH} ./new-exp10.sub
# problems with stray CTLNUL in bash-4.0-alpha
unset a
a=/a
+584
View File
@@ -0,0 +1,584 @@
# must do this because posix mode causes process substitution to be disabled
# and flagged as a syntax error, which causes the shell to exit
set +o posix
expect()
{
echo expect "$@"
}
HOME=/usr/homes/chet # to make the check against new-exp.right work
expect '<foo bar>'
recho "${undef-"foo bar"}" # should be foo bar
expect '<foo>'
recho "${und="foo"}" # should be foo
expect "<$HOME>"
recho ${HOME-"}"}
expect "<$HOME>"
recho "${HOME-'}'}"
expect "<$HOME>"
recho "${HOME-"}"}"
expect $0: 'HOME: }: syntax error: operand expected (error token is "}")'
recho "${HOME:`echo }`}" # should be a math error -- bad substring substitution
expect unset
_ENV=oops
x=${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}
echo ${x:-unset}
expect "<$HOME>"
recho ${HOME}
expect "<$HOME>"
recho ${HOME:-`echo }`}
expect "<$HOME>"
recho ${HOME:-`echo "}"`}
expect "<$HOME>"
recho "${HOME:-`echo "}"`}"
expect "<$HOME>"
recho "$(echo "${HOME}")"
expect "<$HOME>"
recho "$(echo "$(echo ${HOME})")"
expect "<$HOME>"
recho "$(echo "$(echo "${HOME}")")"
P=*@*
expect '<*@>'
recho "${P%"*"}" #
expect '<*@>'
recho "${P%'*'}" #
expect '<@*>'
recho "${P#\*}" # should be @*
expect '<)>'
recho "$(echo ")")" # should be )
expect '<")">'
recho "$(echo "\")\"")" # should be ")"
foo='abcd '
expect '<-abcd> <->'
recho -${foo}- # should be -abcd -
expect '<-abcd> <->'
recho -${foo% *}- # should be -abcd -
expect '<-abcd->'
recho -${foo%% *}- # should be -abcd-
foo=bar
expect '<bar foo>'
echo -n $foo' ' ; echo foo
expect '<bar foo>'
echo -n $foo" " ; echo foo
expect '<bar foo>'
echo -n "$foo " ; echo foo
expect '<barfoo>'
echo -e "$foo\c " ; echo foo
expect '<barfoo>'
echo -e $foo"\c " ; echo foo
# make sure backslashes are preserved in front of characters that are not
# valid backslash escapes
expect '<\x>'
echo -e '\x'
# substring tests
z=abcdefghijklmnop
expect '<abcd>'
recho ${z:0:4}
expect '<efg> <nop>'
recho ${z:4:3} ${z:${#z}-3:3}
expect '<efg> <nop>'
recho ${z:4:3} ${z: -3:3}
expect '<hijklmnop>'
recho ${z:7:30}
expect '<abcdefghijklmnop>'
recho ${z:0:100}
expect '<abcdefghijklmnop>'
recho ${z:0:${#z}}
set 'ab cd' 'ef' 'gh ij' 'kl mn' 'op'
expect '<ab cd> <ef>'
recho "${@:1:2}"
expect '<gh ij> <kl mn>'
recho "${@:3:2}"
expect '<gh ij> <kl mn> <op>'
recho "${@:3:4}"
expect '<ab cd> <ef> <gh ij> <kl mn> <op>'
recho "${@:1:$#}"
# code to ad-hoc parse arithmetic expressions in substring expansions was
# broken until post-2.04
base=/home/chet/foo//bar
string1=$base/abcabcabc
x=1 j=4
expect '</home/chet/foo//bar/abcabcabc>'
recho ${string1:0}
expect '<home/chet/foo//bar/abcabcabc>'
recho ${string1:1}
expect '<home>'
recho ${string1:(j?1:0):j}
expect '<home>'
recho ${string1:j?1:0:j}
expect '<home>'
recho ${string1:(j?(x?1:0):0):j}
expect '<home>'
recho ${string1:j?(x?1:0):0:j}
unset base string1 x j
# indirect variable references
expect '<abcdefghijklmnop>'
recho ${!9:-$z}
ef=4
expect '<4>'
recho ${!2}
expect '<op>'
recho ${!#}
set a b c d e
a=
expect '<abcdefghijklmnop>'
recho ${a:-$z}
expect '<abcdefghijklmnop>'
recho ${!1:-$z}
expect nothing
recho ${a-$z}
expect nothing
recho ${!1-$z}
set -u
expect $0: ABX: unbound variable
( recho ${ABX} )
set +u
expect $0: '$6: cannot assign in this way'
recho ${6="arg6"}
v=abcde
# sed-like variable substitution
expect '<xxcde>'
recho ${v/a[a-z]/xx}
expect '<axxde>'
recho ${v/a??/axx}
expect '<abxyz>'
recho ${v/c??/xyz}
expect '<abbcde>'
recho ${v/#a/ab}
expect '<abcde>'
recho ${v/#d/ab}
expect '<abcabe>'
recho ${v/d/ab}
expect '<abcdlast>'
recho ${v/%?/last}
expect '<abcde>'
recho ${v/%x/last}
av=(abcd efgh ijkl mnop qrst uvwx)
expect '<xxcd>'
recho ${av/??/xx}
expect '<abxx>'
recho ${av/%??/xx}
expect '<xxgh>'
recho ${av[1]/??/xx}
expect '<efgh>'
recho ${av[1]/%ab/xx}
expect '<xxfgh>'
recho ${av[1]/#?/xx}
expect '<zagh>'
recho ${av[1]/??/za}
expect '<zaza>'
recho ${av[1]//??/za}
expect '<zagh>'
recho ${av[1]/#??/za}
expect '<efza>'
recho ${av[1]/%??/za}
expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
recho ${av[@]/*/yyy}
expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
recho ${av[@]/#*/yyy}
expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
recho ${av[@]/%*/yyy}
expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
recho ${av[@]/a*/yyy}
expect '<abxx> <efxx> <ijxx> <mnxx> <qrxx> <uvxx>'
recho ${av[@]/%??/xx}
set abcd efgh ijkl mnop qrst uvwx
expect '<xxcd>'
recho ${1/??/xx}
expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
recho ${@/??/xx}
expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'
recho ${@/%??/xx}
expect '<zaza>'
recho ${3//??/za}
expect '<efza>'
recho ${3/%??/za}
expect '<zaza> <zaza> <zaza> <zaza> <zaza> <zaza>'
recho ${@//??/za}
expect '<zacd> <zagh> <zakl> <zaop> <zast> <zawx>'
recho ${@/#??/za}
expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'
recho ${@//*/yyy}
expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'
recho ${@//a*/yyy}
expect '<abcd> <efgh> <ijkl> <mnop> <qrst> <uvwyyy>'
recho ${@/%x*/yyy}
expect a newline
echo $abmcde
# sneaky way to replace a newline in a variable value with something else
AVAR=$'This\nstring\nhas\nmultiple\nlines.'
echo "${AVAR}"
eval BVAR=\"\${AVAR//$'\n'/-}\"
echo "$BVAR"
unset AVAR BVAR
# run process substitution tests in a subshell so that syntax errors
# caused by a shell not implementing process substitution (e.g., one
# built on a NeXT) will not cause the whole test to exit prematurely
${THIS_SH} ./new-exp1.sub
# run the tests of $(<filename) in a subshell to avoid cluttering up
# this script
${THIS_SH} ./new-exp2.sub
expect '<6>'
recho ${#:-foo}
expect $0: '${#:}: bad substitution'
echo ${#:}
expect "<'>"
recho "'"
expect '<">'
recho '"'
expect '<"hello">'
recho "\"hello\""
shift $#
unset foo
z=abcdef
z1='abc def'
expect '<>'
recho ${foo:-""}
expect nothing
recho ${foo:-"$@"}
expect '<>'
recho "${foo:-$@}"
# unset var
expect '<>'
recho ${foo:-"$zbcd"}
expect nothing
recho ${foo:-$zbcd}
# set var
expect '<abcdef>'
recho ${foo:-"$z"}
expect '<abc def>'
recho ${foo:-"$z1"}
expect '<abcdef>'
recho ${foo:-$z}
expect '<abc> <def>'
recho ${foo:-$z1}
expect '<abcdef>'
recho "${foo:-$z}"
expect '<abc def>'
recho "${foo:-$z1}"
expect '<abcdef>'
recho "${foo:-"$z"}"
# this disagrees with sh and ksh, but I think it is right according
# to posix.2.
expect '<abc def>'
recho "${foo:-"$z1"}"
set ab cd ef gh
expect '<ab> <cd> <ef> <gh>'
recho ${foo:-"$@"}
expect '<ab> <cd> <ef> <gh>'
recho "${foo:-$@}"
expect '<ab> <cd> <ef> <gh>'
recho "${foo:-"$@"}"
shift $#
expect nothing
recho $xxx"$@"
expect nothing
recho ${foo:-$xxx"$@"}
expect '<>'
recho "${foo:-$xxx$@}"
expect '<>'
recho "${foo:-$xxx"$@"}"
expect nothing
recho $xxx"$@"
expect nothing
recho "$xxx$@"
expect nothing
recho "$@"$xxx
expect '<>'
recho $xxx""
expect '<>'
recho $xxx''
expect '<>'
recho ''$xxx
expect '<>'
recho ""$xxx
AB='abcdefghijklmnopqrstuvwxyz'
recho ${AB:7:15}
recho ${AB:15:7}
recho ${AB:20}
recho ${AB:0}
recho ${AB:0:20}
recho ${AB:10:7}
recho ${AB:10:3+4}
recho ${AB:20/2:3+4}
set 1 2 3 4 5 6
recho \""${*:2:2}"\"
IFS=:
recho \""${*:2:2}"\"
IFS=$' \t\n'
z=123456
recho \""${z:2:2}"\"
recho \""${z:2}"\"
recho \""${z:2:4}"\"
recho \""${z:2:6}"\"
set $'\1' $'\2' $'\177'
recho $*
recho $@
recho ${*}
recho ${@}
xx=one/two/two
recho ${xx%/*}
recho ${xx/\/two}
yy=oneonetwo
recho ${yy//one}
recho ${yy/\/one}
xx=oneonetwo
recho ${xx/one}
recho ${xx//one}
recho ${xx/\/one}
# out-of-range substrings
var=abc
c=${var:3}
expect nothing
recho $c
c=${var:4}
expect nothing
recho $c
# as of bash-4.2, negative LENGTH means offset from the end
c=${var:0:-2}
expect '<a>'
recho $c
var=abcdefghi
c=${var:3:12}
recho $c
c=${var:4:20}
recho $c
# make sure null patterns work
xxx=endocrine
yyy=n
unset zzz
recho ${xxx/$yyy/*}
recho ${xxx//$yyy/*}
recho ${xxx/$zzz/*}
recho ${xxx//$zzz/*}
recho ${xxx//%${zzz}/}
recho ${xxx//%${zzz}}
recho ${xxx//#${zzz}/}
recho ${xxx//#${zzz}}
# another case that caused a core dump in bash-2.0
XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbin
recho ${XPATH//:/ }
xx=(ar as at au av aw ax ay az)
recho ${xx[@]/a/}
recho ${xx[@]//a/}
recho ${xx[*]/a/}
recho ${xx[*]//a/}
recho ${xx[@]%?}
recho ${xx[*]%?}
recho ${xx[@]#?}
recho ${xx[*]#?}
set -- ar as at au av aw ax ay az
recho ${@/a/}
recho ${@//a/}
recho ${*/a/}
recho ${*//a/}
recho ${@%?}
recho ${*%?}
recho ${@#?}
recho ${*#?}
shift $#
set -u
( recho $9 ; echo after 1)
( recho ${9} ; echo after 2)
( recho $UNSET ; echo after 3)
( recho ${UNSET} ; echo after 4)
( recho "$UNSET" ; echo after 5)
( recho "${UNSET}" ; echo after 6)
( recho "${#UNSET}" ; echo after 7)
set +u
RECEIVED="12345"
recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
RECEIVED="12345#"
recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
RECEIVED="#"
recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
RECEIVED=""
recho "${RECEIVED:$((${#RECEIVED}-1)):1}"
# tests of new prefix expansion ${!prefix*}
${THIS_SH} ./new-exp3.sub
# bug with indirect expansion through bash-2.05b
${THIS_SH} ./new-exp4.sub
# these caused errors and core dumps in versions before bash-2.04
c=""
echo ${c//${$(($#-1))}/x/}
set a b c d e f g
recho "$@"
set -- ${@:1:$(($# - 2))}
recho "$@"
set a b
recho ${@:1:$(($# - 2))}
recho ${@:1:0}
recho ${@:1:1}
recho ${@:1:2}
recho "${*:1:0}"
# this is an error -- negative expression
set a
recho ${@:1:$(($# - 2))}
XPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:.:/sbin:/usr/sbin
set $( IFS=: ; echo $XPATH )
recho ${@##*/}
recho ${@%%[!/]*}
recho ${@#/*}
recho ${@%*/}
set /full/path/to/x16 /another/full/path
recho ${1%/*}
recho ${1%%[!/]*}
recho ${1#*/}
recho ${1##*/}
${THIS_SH} ./new-exp5.sub
unset var
var=blah
# these had better agree
echo ${var[@]:3}
echo ${var:3}
echo ${var[@]/#/--}
echo ${var/#/--}
echo ${var[@]##?}
echo ${var##?}
unset var
var=(abcde abcfg abchi)
# problems with anchoring pattern replacements
echo ${var[*]//#abc/foo}
echo ${var[*]/#abc/foo}
unset var
${THIS_SH} ./new-exp6.sub
${THIS_SH} ./new-exp7.sub
${THIS_SH} ./new-exp8.sub
# tests to check whether things like indirect expansion of a variable whose
# value is 'anothervar[@]' stop working
${THIS_SH} ./new-exp9.sub
# problems with stray CTLNUL in bash-4.0-alpha
unset a
a=/a
recho "/${a%/*}"
recho "/${a///a/}"
# this must be last!
expect $0: 'ABXD: parameter unset'
recho ${ABXD:?"parameter unset"}
+86
View File
@@ -0,0 +1,86 @@
# new framework for parameter transformations, post bash-4.3
printf "<%s>" "${x@Q}" ; echo
printf "<%s>" "${x@E}" ; echo
printf "<%s>" "${x@P}" ; echo
printf "<%s>" "${x@A}" ; echo
x="ab 'cd' ef"
printf "<%s> " "${x@Q}" ; echo
printf "<%s>" "${x@C}"
# if unquoted, normal word splitting happens
set -- ab 'cd ef' '' gh
printf "<%s> " "${@@Q}" ; echo
printf "<%s> " "${*@Q}" ; echo
printf "<%s> " ${@@Q} ; echo
printf "<%s> " ${*@Q} ; echo
y[0]=4
y[1]='ab cd'
printf "<%s> " "${y[1]@Q}" ; echo
printf "<%s> " "${y[@]@Q}" ; echo # mksh doesn't like @ or * or arrays subscripted with them
printf "<%s> " "${z@Q}" ; echo # empty string?
recho ${z@Q} # this disappears
#
HOST=host
SHELL_LEVEL=2
NPS1='\[\]${HOST}($SHELL_LEVEL)[\v]\$ '
recho "${NPS1@P}"
#
D=' \t\n'
printf "<%s>" "${D@E}" ; echo
printf "<%s>" "${D@Q}" ; echo
E=$' \t\n'
printf "<%s>" "${E@E}" ; echo
printf "<%s>" "${E@Q}" ; echo
declare x
declare -r x="ab 'cd' ef"
printf "%s" "${x@A}" ; echo
set -- ab 'cd ef' '' gh
printf "%s " "${@@A}" ; echo
A=( "$@" )
printf "%s " "${A[@]@A}" ; echo
B=()
printf "%s " "${B[@]@A}" ; echo
unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A[@]@A}" ; echo
unset X
declare X
declare -r X="ab 'cd' ef"
printf "%s" "${X@a}" ; echo
set -- 1 2 3 4
unset A
A=( "$@" )
printf "%s " "${A@a}" ; echo
unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A@a}" ; echo
declare -ir Y=0
printf "%s" "${Y@a}" ; echo
# make sure we still handle ${#@} and ${@} as posix requires
set -- a b c d e
echo ${@}
echo ${#@}
echo a${#@}b
+85
View File
@@ -0,0 +1,85 @@
# new framework for parameter transformations, post bash-4.3
printf "<%s>" "${x@Q}" ; echo
printf "<%s>" "${x@E}" ; echo
printf "<%s>" "${x@P}" ; echo
printf "<%s>" "${x@A}" ; echo
x="ab 'cd' ef"
printf "<%s> " "${x@Q}" ; echo
printf "<%s>" "${x@C}"
# if unquoted, normal word splitting happens
set -- ab 'cd ef' '' gh
printf "<%s> " "${@@Q}" ; echo
printf "<%s> " "${*@Q}" ; echo
printf "<%s> " ${@@Q} ; echo
printf "<%s> " ${*@Q} ; echo
y[0]=4
y[1]='ab cd'
printf "<%s> " "${y[1]@Q}" ; echo
printf "<%s> " "${y[@]@Q}" ; echo # mksh doesn't like @ or * or arrays subscripted with them
printf "<%s> " "${z@Q}" ; echo # empty string?
recho ${z@Q} # this disappears
#
HOST=host
PS1='\[\]${HOST}($SHLVL)[\v]\$ '
recho "${PS1@P}"
#
D=' \t\n'
printf "<%s>" "${D@E}" ; echo
printf "<%s>" "${D@Q}" ; echo
E=$' \t\n'
printf "<%s>" "${E@E}" ; echo
printf "<%s>" "${E@Q}" ; echo
declare x
declare -r x="ab 'cd' ef"
printf "%s" "${x@A}" ; echo
set -- ab 'cd ef' '' gh
printf "%s " "${@@A}" ; echo
A=( "$@" )
printf "%s " "${A[@]@A}" ; echo
B=()
printf "%s " "${B[@]@A}" ; echo
unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A[@]@A}" ; echo
unset X
declare X
declare -r X="ab 'cd' ef"
printf "%s" "${X@a}" ; echo
set -- 1 2 3 4
unset A
A=( "$@" )
printf "%s " "${A@a}" ; echo
unset A
declare -A A
A=( [one]=1 [two]='b c' [three]='' [four]=de )
printf "%s " "${A@a}" ; echo
declare -ir Y=0
printf "%s" "${Y@a}" ; echo
# make sure we still handle ${#@} and ${@} as posix requires
set -- a b c d e
echo ${@}
echo ${#@}
echo a${#@}b
+9
View File
@@ -66,6 +66,15 @@ declare -ar FOOBAR2='([0]="bar")'
declare -ar FOOBAR2='([0]="bar")'
F OUTSIDE
F OUTSIDE
declare -ar outside='()'
declare -ir outside1="1"
tempenv = foo
0
declare -ar myvar='([0]="0")'
1
declare -ir myvar="1"
declare -rx tempvar1='foo'
declare -rx tempvar2='qux'
a=z
a=b
a=z
+3 -1
View File
@@ -214,6 +214,8 @@ ${THIS_SH} ./varenv5.sub
# variable scoping in the presence of nameref
${THIS_SH} ./varenv6.sub
# variable declaration problems with arrays and readonly local variables
${THIS_SH} ./varenv7.sub
# make sure variable scoping is done right
tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a
+219
View File
@@ -0,0 +1,219 @@
#
# varenv.sh
#
# Test the behavior of the shell with respect to variable and environment
# assignments
#
expect()
{
echo expect "$@"
}
a=1
b=2
c=3
d=4
e=5
f=6 g=7 h=8
a=3 b=4 $CHMOD $MODE $FN
# This should echo "3 4" according to Posix.2
expect "3 4"
echo $a $b
set -k
# Assignment statements made when no words are left affect the shell's
# environment
a=5 b=6 $CHMOD c=7 $MODE d=8 $FN e=9
expect "5 6 7 8 9"
echo $a $b $c $d $e
$CHMOD f=7 $MODE g=8 $FN h=9
expect "7 8 9"
echo $f $g $h
set +k
# The temporary environment does not affect variable expansion, only the
# environment given to the command
export HOME=/usr/chet
expect $HOME
echo $HOME
expect $HOME
HOME=/a/b/c /bin/echo $HOME
expect $HOME
echo $HOME
# This should echo /a/b/c
expect /a/b/c
HOME=/a/b/c printenv HOME
set -k
# This should echo $HOME 9, NOT /a/b/c 9
expect "$HOME"
HOME=/a/b/c /bin/echo $HOME c=9
expect "$HOME 7"
echo $HOME $c
# I claim the next two echo calls should give identical output.
# ksh agrees, the System V.3 sh does not
expect "/a/b/c 9 /a/b/c"
HOME=/a/b/c $ECHO a=$HOME c=9
echo $HOME $c $a
expect "/a/b/c 9 /a/b/c"
HOME=/a/b/c a=$HOME c=9
echo $HOME $c $a
set +k
# How do assignment statements affect subsequent assignments on the same
# line?
expect "/a/b/c /a/b/c"
HOME=/a/b/c a=$HOME
echo $HOME $a
# The system V.3 sh does this wrong; the last echo should output "1 1",
# but the system V.3 sh has it output "2 2". Posix.2 says the assignment
# statements are processed left-to-right. bash and ksh output the right
# thing
c=1
d=2
expect "1 2"
echo $c $d
d=$c c=$d
expect "1 1"
echo $c $d
# just for completeness
unset d c
expect unset
echo ${d-unset}
# no output
export a
a=bcde
export a
/bin/true 2>/dev/null
func()
{
local YYZ
YYZ="song by rush"
echo $YYZ
echo $A
}
YYZ="toronto airport"
A="AVAR"
echo $YYZ
echo $A
A=BVAR func
echo $YYZ
echo $A
export A
# Make sure expansion doesn't use assignment statements preceding a builtin
A=ZVAR echo $A
XPATH=/bin:/usr/bin:/usr/local/bin:.
func2()
{
local z=yy
local -a avar=( ${XPATH//: } )
echo ${avar[@]}
local
}
avar=42
echo $avar
func2
echo $avar
# try to set an attribute for an unset variable; make sure it persists
# when the variable is assigned a value
declare -i ivar
ivar=10
declare -p ivar
unset ivar
# export an unset variable, make sure it is not suddenly set, but make
# sure the export attribute persists when the variable is assigned a
# value
export ivar
echo ${ivar-unset}
ivar=42
declare -p ivar
# make sure set [-+]o ignoreeof and $IGNOREEOF are reflected
unset IGNOREEOF
set +o ignoreeof
set -o ignoreeof
if [ "$IGNOREEOF" -ne 10 ]; then
echo "./varenv.sh: set -o ignoreeof is not reflected in IGNOREEOF" >&2
fi
unset IGNOREEOF
set +o ignoreeof
# older versions of bash used to not reset RANDOM in subshells correctly
[[ $RANDOM -eq $(echo $RANDOM) ]] && echo "RANDOM: problem with subshells"
# make sure that shopt -o is reflected in $SHELLOPTS
# first, get rid of things that might be set automatically via shell
# variables
set +o posix
set +o ignoreeof
set +o monitor
echo $-
echo ${SHELLOPTS}
shopt -so physical
echo $-
echo ${SHELLOPTS}
# and make sure it is readonly
readonly -p | grep SHELLOPTS
# This was an error in bash versions prior to bash-2.04. The `set -a'
# should cause the assignment statement that's an argument to typeset
# to create an exported variable
unset FOOFOO
FOOFOO=bar
set -a
typeset FOOFOO=abcde
printenv FOOFOO
# test out export behavior of variable assignments preceding builtins and
# functions
$THIS_SH ./varenv1.sub
# more tests; bugs in bash up to version 2.05a
$THIS_SH ./varenv2.sub
# more tests; bugs in bash IFS scoping up through version 4.2
$THIS_SH ./varenv3.sub
# scoping problems with declare -g through bash-4.2
${THIS_SH} ./varenv4.sub
# more scoping and declaration problems with -g and arrays through bash-4.2
${THIS_SH} ./varenv5.sub
# variable scoping in the presence of nameref
${THIS_SH} ./varenv6.sub
# make sure variable scoping is done right
tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a
+37
View File
@@ -0,0 +1,37 @@
foo()
{
local -a myvar=()
local -r myvar=0
echo "${myvar[@]}"
declare -p myvar
}
foo2()
{
local -i myvar=0
local -r myvar=1
echo "${myvar}"
declare -p myvar
}
declare -a outside=()
declare -r outside
declare -p outside
outside1=1
declare -ir outside1
declare -p outside1
tempenv=foo declare -r tempenv
echo tempenv = $tempenv
foo
foo2
tempvar1=foo declare -r tempvar1
echo ${tempvar1@A}
tempvar2=bar declare -r tempvar2=qux
echo ${tempvar2@A}