bash-5.0-beta release

This commit is contained in:
Chet Ramey
2018-09-17 15:10:56 -04:00
parent 9a51695bed
commit 2f5dfe5a18
144 changed files with 27560 additions and 36005 deletions
+120
View File
@@ -621,3 +621,123 @@ arithmetic:
6.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="11" )
7.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="11" )
8.declare -A a=([" "]="13" [0]="0" [1]="1" ["\" \""]="13" )
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa+bb>
argv[1] = <xa+bb>
argv[1] = <xa+bb>
argv[2] = <xa+bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa+bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xabb>
argv[1] = <xabb>
argv[1] = <xabb>
argv[2] = <xabb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xa>
argv[2] = <bb>
argv[1] = <xabb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa+bb>
argv[2] = <aa+bb>
argv[1] = <aa>
argv[2] = <bb>
argv[3] = <aa>
argv[4] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa>
argv[2] = <bb>
argv[1] = <aa+bb>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[3] = <a>
argv[4] = <b>
argv[1] = <a+b>
argv[2] = <a+b>
argv[1] = <a>
argv[2] = <b>
argv[3] = <a>
argv[4] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a>
argv[2] = <b>
argv[1] = <a+b>
+1
View File
@@ -404,3 +404,4 @@ ${THIS_SH} ./array22.sub
${THIS_SH} ./array23.sub
${THIS_SH} ./array24.sub
${THIS_SH} ./array25.sub
${THIS_SH} ./array26.sub
+118
View File
@@ -0,0 +1,118 @@
# these should produce the same results
a=(aa bb)
set -- aa bb
IFS=+
recho ${a[@]}
recho ${a[@]:0}
recho $@
recho ${@:1}
A=${a[*]} B=${a[*]:0}
recho $* ${*:1}
recho ${a[*]} ${a[*]:0}
recho "$A" "$B"
recho $A $B
unset A B
recho ${@/a/x}
recho ${a[@]/a/x}
recho "${@/a/x}"
recho "${a[@]/a/x}"
recho ${*/a/x}
recho ${a[*]/a/x}
recho "${*/a/x}"
recho "${a[*]/a/x}"
A=${*/a/x}
B=${a[*]/a/x}
recho "$A" "$B"
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]/a/x}
recho "${A[@]/a/x}"
recho ${A[*]/a/x}
recho "${A[*]/a/x}"
unset A
IFS=
recho ${@/a/x}
recho ${a[@]/a/x}
recho "${@/a/x}"
recho "${a[@]/a/x}"
recho ${*/a/x}
recho ${a[*]/a/x}
recho "${*/a/x}"
recho "${a[*]/a/x}"
A=${*/a/x}
B=${a[*]/a/x}
recho "$A" "$B"
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]/a/x}
recho "${A[@]/a/x}"
recho ${A[*]/a/x}
recho "${A[*]/a/x}"
unset A
IFS=+
recho ${a[@]}
recho ${a[@],,}
recho "${a[@]}"
recho "${a[@],,}"
A=${a[*]} B=${a[*],,}
recho $* ${*,,}
recho ${a[*]} ${a[*],,}
recho "${a[*]}" "${a[*],,}"
recho "$A" "$B"
recho $A $B
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@],,}
recho "${A[@],,}"
recho ${A[*],,}
recho "${A[*],,}"
unset A
recho ${a[@]#?}
recho ${@#?}
A=${a[*]#?} B=${a[*]#?}
recho ${*#?} ${a[*]#?}
recho "$A" "$B"
recho $A $B
unset A B
declare -A A
A[0]=aa
A[1]=bb
recho ${A[@]#?}
recho "${A[@]#?}"
recho ${A[*]#?}
recho "${A[*]#?}"
+9
View File
@@ -220,3 +220,12 @@ declare -A a=(["80's"]="Depeche Mode" )
1+5
declare -A a=(["\$(date >&2)"]="5" )
declare -A myarray=([foo]="bleh" ["foo[bar"]="bleh" )
./assoc10.sub: line 1: declare: a: cannot convert indexed to associative array
f: declare -a a
./assoc10.sub: line 4: declare: a: cannot convert associative to indexed array
f: declare -A a
f: declare -a a
main: declare -- a="7"
f: declare -A a
main: declare -- a="42"
+2
View File
@@ -217,3 +217,5 @@ ${THIS_SH} ./assoc8.sub
# new shopt option to prevent multiple expansion of assoc array subscripts
${THIS_SH} ./assoc9.sub
${THIS_SH} ./assoc10.sub
+17
View File
@@ -0,0 +1,17 @@
f() { declare -a a; declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
f
f() { declare -A a; declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
f
echo
f() { declare -a a; echo -n "$FUNCNAME: " ; declare -p a; }
a=7
f
echo -n 'main: '; declare -p a
f() { declare -A a; echo -n "$FUNCNAME: " ; declare -p a; }
a=42
f
echo -n 'main: '; declare -p a
+37
View File
@@ -203,3 +203,40 @@ d
e
! !
./histexp4.sub: line 20: !': event not found
/tmp/Step1
echo /$(echo tmp)/Step1
/tmp/Step1
echo /<(echo tmp)/Step1 > /dev/null
/tmp/Step1
echo $(echo /tmp)/Step1
/tmp/Step1
echo <(echo /tmp)/Step1 > /dev/null
/+(one|two|three)/Step1
echo /+(one|two|three)/Step1
/+(one|two|three)/Step1
/*(tmp|dev|usr)/Step1
echo /*(tmp|dev|usr)/Step1
/*(tmp|dev|usr)/Step1
+(/one|/two|/three)/Step1
echo +(/one|/two|/three)/Step1
+(/one|/two|/three)/Step1
*(/tmp|/dev|/usr)/Step1
echo *(/tmp|/dev|/usr)/Step1
*(/tmp|/dev|/usr)/Step1
one
echo echo one
echo one
echo one
echo one
1 set -o histexpand
2 echo one
3 for f in a b c; do echo echo one; done
4 history
two
echo echo two
echo two
echo two
echo two
1 echo two
2 for f in a b c; do echo echo two; done
3 history
+2
View File
@@ -140,3 +140,5 @@ ${THIS_SH} ./histexp1.sub
${THIS_SH} ./histexp2.sub
${THIS_SH} ./histexp3.sub
${THIS_SH} ./histexp4.sub
${THIS_SH} ./histexp5.sub
${THIS_SH} ./histexp6.sub
+28
View File
@@ -0,0 +1,28 @@
set -o history
set -o histexpand
# command and process substitutions should be tokenized as a single word
echo /$(echo tmp)/Step1
echo !:*
echo /<(echo tmp)/Step1 >/dev/null
echo !:*
# same tests at the beginning of a word
echo $(echo /tmp)/Step1
echo !:*
echo <(echo /tmp)/Step1 >/dev/null
echo !:*
# so should shell extended glob patterns
shopt -s extglob
echo /+(one|two|three)/Step1
echo !:*
echo /*(tmp|dev|usr)/Step1
echo !:*
# same tests at the beginning of a word
echo +(/one|/two|/three)/Step1
echo !:*
echo *(/tmp|/dev|/usr)/Step1
echo !:*
+24
View File
@@ -0,0 +1,24 @@
unset HISTIGNORE
HISTFILE=$TMPDIR/bashhist-$$
set -o history
set -o histexpand
echo one
for f in a b c; do
echo !!
done
history
history -c
echo two
for f in a b c; do
echo !-1
done
history
set +o history
rm -f $HISTFILE
+3 -2
View File
@@ -50,7 +50,8 @@ Passed all 1378 Unicode tests
0000003
0000000 101 040 302 243 040 305 222 012
0000010
./unicode3.sub: line 3: $'5\247@3\231+\306S8\237\242\352\263': command not found
./unicode3.sub: line 5: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory
./unicode3.sub: line 5: $'5\247@3\231+\306S8\237\242\352\263': command not found
./unicode3.sub: line 7: cd: $'5\247@3\231+\306S8\237\242\352\263': No such file or directory
$'5\247@3\231+\306S8\237\242\352\263'
+ : $'5\247@3\231+\306S8\237\242\352\263'
+ set +x
+43
View File
@@ -440,3 +440,46 @@ declare -n foo="bar"
declare -- bar
declare -- foo="bar"
declare -- bar
declare -a v=([0]="Y")
r: <Y>
v: <Y>
declare -n ref="var"
declare -a var=([0]="X")
declare -n ref="var"
declare -a var=([0]="X")
declare -n ref="var"
./nameref20.sub: line 23: declare: var: not found
outside:
declare -a foo=([0]="X")
declare -n ref="var"
declare -a var=([0]="X")
outside:
./nameref20.sub: line 38: declare: ref: not found
./nameref20.sub: line 38: declare: var: not found
declare -n ref="var"
declare -- var="X"
outside:
./nameref20.sub: line 45: declare: ref: not found
./nameref20.sub: line 45: declare: var: not found
declare -n ref="var"
declare -a var=([0]="Y")
declare -- ref="Y"
declare -- var="X"
ref=Y
declare -- ref="Y"
./nameref20.sub: line 61: declare: var: not found
ref=Y
declare -n ref="var"
declare -A var=([2]="" )
declare -n ref="var"
declare -A var=([2]="" )
declare -n ref="var"
declare -a var=([2]="")
declare -n ref="var"
declare -a var=([2]="")
declare -n ref="var"
declare -ai var=([1]="0")
declare -n ref="var"
declare -ai var=([1]="0")
declare -n ref="var"
declare -- var="1"
+71
View File
@@ -0,0 +1,71 @@
# a collection of cases in bug reports after bash-5.0-alpha was released
declare -n r=v[0]
v=(X); r=Y
declare -p ${!v*}
printf "%s: <%s>\n" "r" "$r" "v" "$v"
unset -n r
unset -v v
declare -n ref=var; declare -a ref
ref=(X)
declare -p ref var
unset -n ref
unset -v var
f() { declare -n ref=var; declare ref=(X); declare -p ref var; };
f
unset -f f
f() { declare -n ref=var; declare -g ref=(X); declare -p ref var; };
declare -n ref=foo
f
echo outside:
declare -p foo
unset -n ref
unset -v foo
unset -f f
f() { declare -n ref=var; declare -a ref; ref=(X); declare -p ref var; }
f
echo outside:
declare -p ref var
unset -f f
f() { declare -n ref=var; declare ref; ref=X; declare -p ref var; }
f
echo outside:
declare -p ref var
unset -f f
unset -n ref; unset var
f()
{
declare var=X; declare -n ref=var; declare ref=(Y)
declare -p ref var
}
f
unset -f f
declare -n ref=var
f() { local ref=Y; declare -p ref var; local; }
var=X
f
unset -v var
f
unset -n ref
unset -f f
+56
View File
@@ -0,0 +1,56 @@
# issues with local variables and local namerefs post-bash-4.4
f()
{
local -n ref=var
local -A ref=([1]=)
# declare -p ref var
ref=([2]=)
declare -p ref var
}
unset ref var
f
unset ref; var=0
f
unset var
unset -f f
f()
{
local -n ref=var
local -a ref=([1]=)
ref=([2]=)
declare -p ref var
}
unset ref var
f
unset ref; var=0
f
unset var
unset -f f
f() { local -n ref=var; local -i ref=([1]=); declare -p ref var; }
unset var
f
var=0
f
unset var
unset -f f
f() { local -n ref=var; local ref=1; declare -p ref var; }
var=0
f
unset var
unset -f f
+10
View File
@@ -119,3 +119,13 @@ argv[3] = <uv^Aw^Axy>
argv[1] = <@2>
argv[2] = <uv^Aw^Axy>
argv[3] = <uv^Aw^Axy>
argv[1] = <aa1>
argv[2] = <uv^A^A>
argv[1] = <aa2>
argv[2] = <uv^A^A>
argv[1] = <aa3>
argv[2] = <uv^A^Awx>
argv[3] = <uv^A^Awx>
argv[1] = <aa4>
argv[2] = <uv^A^Awx>
argv[3] = <uv^A^Awx>
+9
View File
@@ -95,3 +95,12 @@ recho d2 "${1:2:2}"
recho @1 ${@:1:2}
recho @2 "${@:1:2}"
declare -A assoc
assoc=( [0]=$e [1]=$e )
recho aa1 ${assoc:0:4}
recho aa2 "${assoc:0:4}"
recho aa3 ${assoc[@]:0:2}
recho aa4 "${assoc[@]:0:2}"
+6 -2
View File
@@ -275,5 +275,9 @@ argv[2] = <b>
[ abc def ghi jkl / abc def ghi jkl ]
[ abc def ghi jkl ]
[ abc def ghi jkl / abc def ghi jkl / abc def ghi jkl ]
./posixexp.tests: line 82: unexpected EOF while looking for matching `}'
./posixexp.tests: line 83: syntax error: unexpected end of file
5: notOK
OK
OK
5: $'not\ttoo\nbad'
./posixexp.tests: line 83: unexpected EOF while looking for matching `}'
./posixexp.tests: line 84: syntax error: unexpected end of file
+1
View File
@@ -76,6 +76,7 @@ ${THIS_SH} ./posixexp3.sub
${THIS_SH} ./posixexp4.sub
${THIS_SH} ./posixexp5.sub
${THIS_SH} ./posixexp6.sub
${THIS_SH} ./posixexp7.sub
# this will be an error
foo=bar
+1 -1
View File
@@ -7,7 +7,7 @@ teststring=$(printf '\1\2\3\177')
n=0
trim_od() {
od -a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }'
od -t a | sed -n '1 { s/^0*[[:blank:]]*//; s/[[:blank:]]*$//; p; }'
}
doTest() {
+13
View File
@@ -0,0 +1,13 @@
# test the effect of quotes on the WORD in the posix pattern removal operators
# a here document does not behave the same as double quotes
x=notOK
cat <<EOF
5: ${x#$'not'}
EOF
echo "${x#'not'}"
echo "${x#$'not'}"
cat <<EOF
5: $'not\ttoo\nbad'
EOF
+34
View File
@@ -86,3 +86,37 @@ test'string
a'b'c
foo b c baz
foo 'bar baz
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
=====
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
=====
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
=====
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
argv[1] = <>
+1
View File
@@ -121,3 +121,4 @@ echo "${foo:-string \\}"
echo ${foo:-string \\\}}
${THIS_SH} ./quote1.sub
${THIS_SH} ./quote2.sub
+42
View File
@@ -0,0 +1,42 @@
x=x
e=
recho ${x:+""}
recho ${x:+ ""}
recho ${x:+"" }
recho ${x:+"$e"}
recho ${x:+ "$e"}
recho ${x:+"$e""$e"""}
recho ${x:+"$e""$e"""}
recho ${x:+"$e" "$e"""}
recho ${x:+"$e""$e" ""}
recho ${x:+ "$e""$e"""}
echo =====
recho ${x:+''}
recho ${x:+ ''}
recho ${x:+'' }
recho ${x:+'' ''}
recho ${x:+$e''}
recho ${x:+''$e}
recho ${x:+''$e $e''}
echo =====
recho ${x:+"$(:)"}
recho ${x:+ "$(:)"}
recho ${x:+"$(:)""$(:)"""}
recho ${x:+"$(:)""$(:)"""}
recho ${x:+"$(:)" "$(:)"""}
recho ${x:+"$(:)""$(:)" ""}
recho ${x:+ "$(:)""$(:)"""}
echo =====
recho ${x:+"`:`"}
recho ${x:+ "`:`"}
recho ${x:+"`:`""`:`"""}
recho ${x:+"`:`""`:`"""}
recho ${x:+"`:`" "`:`"""}
recho ${x:+"`:`""`:`" ""}
recho ${x:+ "`:`""`:`"""}
+1 -1
View File
@@ -44,7 +44,7 @@ kl
ab
cd
cd
./redir.tests: line 154: redir1.*: No such file or directory
./redir.tests: line 157: redir1.*: No such file or directory
# tests of ksh93-like dup-and-close redirection operators
exec 9<$0
+3
View File
@@ -57,6 +57,9 @@ echo to c 1>&6
cat $TMPDIR/bash-c
echo "Point 5"
# clean up before running scripts
exec 4>&- 5>&- 6<&-
rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c
#
+1 -1
View File
@@ -1,2 +1,2 @@
${THIS_SH} ./varenv.sh 2>&1 | grep -v '^expect' > ${BASH_TSTOUT}
${THIS_SH} ./varenv.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT}
diff ${BASH_TSTOUT} varenv.right && rm -f ${BASH_TSTOUT}
+2 -3
View File
@@ -27,7 +27,7 @@ shopt -u extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
shopt -u globasciiranges
shopt -s globasciiranges
shopt -u globstar
shopt -u gnu_errfmt
shopt -u histappend
@@ -63,6 +63,7 @@ shopt -s complete_fullquote
shopt -s expand_aliases
shopt -s extquote
shopt -s force_fignore
shopt -s globasciiranges
shopt -s hostcomplete
shopt -s interactive_comments
shopt -s progcomp
@@ -89,7 +90,6 @@ shopt -u execfail
shopt -u extdebug
shopt -u extglob
shopt -u failglob
shopt -u globasciiranges
shopt -u globstar
shopt -u gnu_errfmt
shopt -u histappend
@@ -130,7 +130,6 @@ execfail off
extdebug off
extglob off
failglob off
globasciiranges off
globstar off
gnu_errfmt off
histappend off
+1 -1
View File
@@ -9,5 +9,5 @@ _intl_normalize_spaces()
# avoid whitespace differences in wc implementations
_cut_leading_spaces()
{
sed -e 's/^[[:space:]]*//g'
sed -e 's/^[ ]*//g'
}
+4 -1
View File
@@ -1,4 +1,6 @@
export LANG=en_US.UTF-8 # make sure
cd $TMPDIR # try to avoid NFS artifacts
payload=$'\065\247\100\063\231\053\306\123\070\237\242\352\263'
"$payload"
@@ -6,4 +8,5 @@ cd "$payload"
printf %q "$payload"
echo
set -x ; : "$payload"
set -x ; : "$payload" ; set +x
cd $OLDPWD
+60
View File
@@ -145,8 +145,68 @@ outside:
declare -x foo="abc"
inside: declare -x var="value"
outside: declare -- var="one"
inside: declare -x var="value"
outside: declare -x var="value"
inside: declare -- var="local"
outside: declare -x var="global"
foo=<unset> environment foo=
foo=foo environment foo=foo
foo=foo environment foo=foo
./varenv13.sub: line 3: `var[0]': not a valid identifier
./varenv13.sub: line 3: `var[@]': not a valid identifier
./varenv13.sub: line 1: declare: var: not found
./varenv13.sub: line 12: var[@]: bad array subscript
declare -A var=([0]="X" )
help
./varenv13.sub: line 21: `var[0]': not a valid identifier
1
./varenv14.sub: line 6: warning: var: cannot inherit value from incompatible type
declare -a var=([0]="X")
./varenv14.sub: line 9: warning: var: cannot inherit value from incompatible type
declare -a var=([0]="Y")
./varenv14.sub: line 10: warning: var: cannot inherit value from incompatible type
declare -a var=([0]="Y")
./varenv14.sub: line 11: warning: var: cannot inherit value from incompatible type
declare -a var=()
./varenv14.sub: line 12: warning: var: cannot inherit value from incompatible type
declare -a var=()
./varenv14.sub: line 18: f: var: cannot convert indexed to associative array
declare -a a=([0]="X")
declare -a s=([0]="X")
declare -a a=([0]="X" [1]="Y")
declare -a s=([0]="X" [1]="Y")
declare -a a=([0]="XY")
declare -a s=([0]="XY")
f: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
f1: after: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
done: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
f3:1
f3:2
f3:3
f3:4
f3:5
f3:6
f3:7
f3:8
f3:9
f3:10
f3:11
f3:12
f3:13
f3:14
f3:15
f3:16
f3:17
f3:18
f3:19
f3:20
before source: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
varenv15.in: before set: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
varenv15.in: after set: a b c d e f g h i j k l m n o p q r s t u v w x y z
after source 1: a b c d e f g h i j k l m n o p q r s t u v w x y z
varenv15.in: before set: one two three four five six seven eight nine ten
varenv15.in: after set: a b c d e f g h i j k l m n o p q r s t u v w x y z
after source 2: a b c d e f g h i j k l m n o p q r s t u v w x y z
a=z
a=b
a=z
+246
View File
@@ -0,0 +1,246 @@
#
# 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
# variable declaration problems with arrays and readonly local variables
${THIS_SH} ./varenv7.sub
# variable visibility problems with process substitution subshells in
# redirections
${THIS_SH} ./varenv8.sub
# make sure that builtins like readonly and export modify local array variables
# if executed in shell functions, like they modify local scalar variables
${THIS_SH} ./varenv9.sub
# more tests of unset and local variables with dynamic scoping
${THIS_SH} ./varenv10.sub
# tests of compound assignments in function scope
${THIS_SH} ./varenv11.sub
# temporary environment variable propagation and scoping in posix mode
${THIS_SH} ./varenv12.sub
# temporary environment and invalid shell indentifier names
${THIS_SH} ./varenv13.sub
# localvar_inherit
${THIS_SH} ./varenv14.sub
${THIS_SH} ./varenv15.sub
# make sure variable scoping is done right
tt() { typeset a=b;echo a=$a; };a=z;echo a=$a;tt;echo a=$a
+38
View File
@@ -47,6 +47,28 @@ echo -n 'outside: ' ; declare -p var
unset -v var
unset -f func
# this will probably change behavior; export shouldn't behave like this when
# not in posix mode and the sequencing is probably wrong in posix mode. since
# export is a special builtin, the variable assignment should modify the
# global variable, leaving the local variable unchanged. all shells, including
# bash, modify the local variable; bash is the only one that propagates the
# value out to the calling environment. bash does that only when in posix
# mode.
func()
{
local var=inside
var=value export var
echo -n 'inside: ' ; declare -p var
}
var=outside
func
echo -n 'outside: ' ; declare -p var
unset -v var
unset -f func
func()
{
local var=local
@@ -60,3 +82,19 @@ echo -n 'outside: ' ; declare -p var
unset -v var
unset -f func
# test whether or not temporary environment assignments are exported
# in posix mode
showfoo()
{
printf %s "foo=${foo-<unset>}"
echo -n ' environment foo='
printenv foo || echo
}
unset foo
showfoo
foo=foo showfoo
showfoo
unset -v foo
unset -f showfoo
+23
View File
@@ -0,0 +1,23 @@
f() { declare -p ${!var*} | grep ^var; declare -p var ; }
var[0]=X var[@]=Y f
unset -f f
unset -v var
typeset -A var
f() { declare -p ${!var*}; }
var[0]=X var[@]=Y
f
: ${THIS_SH:=./bash}
env 'v[0]=help' ${THIS_SH} -c 'printenv "v[0]"'
unset -v var
f() { test -v 'var[0]'; echo $?; }
var[0]=X f
unset -v var
+33
View File
@@ -0,0 +1,33 @@
# testing framework for local variable inheritence
shopt -s localvar_inherit
declare -A var
f() { declare var+=([0]=X); declare -p var; }
f
f() { declare var=([Y]=Y); declare -p var; }; f
f() { declare var+=([Y]=Y); declare -p var; }; f
f() { declare var+=(); declare -p var; }; f
f() { declare var=(); declare -p var; }; f
unset -f f
unset -v var
declare -a var=( [0]=12 )
f() { declare -A var+=([0]=X); declare -p var; }
f
unset -f f
unset a s
a=(X) s=X
f() { local -a a s; declare -p a s; }
f
f() { local a+=(Y) s+=(Y); declare -p a s; }
f
f() { local -a a+=Y s+=Y; declare -p a s; }
f
+3
View File
@@ -0,0 +1,3 @@
echo varenv15.in: before set: "$@"
set -- a b c d e f g h i j k l m n o p q r s t u v w x y z
echo varenv15.in: after set: "$@"
+38
View File
@@ -0,0 +1,38 @@
# check saving and restoring positional parameters around function calls
f()
{
echo $FUNCNAME: "$@"
}
f1()
{
f {1..50}
echo $FUNCNAME: after: $@
}
set -- {1..100}
f1 {1..20}
echo done: $@
f3()
{
echo $FUNCNAME:$1
shift
if [ $# -le 0 ]; then
return
fi
f3 "$@"
}
f3 {1..20}
# now let's try source with and without positional parameters
set -- {1..20}
echo before source: "$@"
. ./varenv15.in
echo after source 1: "$@"
. ./varenv15.in one two three four five six seven eight nine ten
echo after source 2: "$@"