mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-08 04:40:49 +02:00
bash-4.2 remove leftover and stray files
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
BUILD_DIR=/usr/local/build/chet/bash/bash-current
|
||||
THIS_SH=$BUILD_DIR/bash
|
||||
PATH=$PATH:$BUILD_DIR
|
||||
|
||||
export THIS_SH PATH
|
||||
|
||||
rm -f /tmp/xx
|
||||
|
||||
/bin/sh "$@"
|
||||
@@ -1,291 +0,0 @@
|
||||
set +o posix
|
||||
declare -i iv jv
|
||||
|
||||
iv=$(( 3 + 5 * 32 ))
|
||||
echo $iv
|
||||
iv=iv+3
|
||||
echo $iv
|
||||
iv=2
|
||||
jv=iv
|
||||
|
||||
let "jv *= 2"
|
||||
echo $jv
|
||||
jv=$(( $jv << 2 ))
|
||||
echo $jv
|
||||
|
||||
let jv="$jv / 2"
|
||||
echo $jv
|
||||
jv="jv >> 2"
|
||||
echo $jv
|
||||
|
||||
iv=$((iv+ $jv))
|
||||
echo $iv
|
||||
echo $((iv -= jv))
|
||||
echo $iv
|
||||
echo $(( iv == jv ))
|
||||
echo $(( iv != $jv ))
|
||||
echo $(( iv < jv ))
|
||||
echo $(( $iv > $jv ))
|
||||
echo $(( iv <= $jv ))
|
||||
echo $(( $iv >= jv ))
|
||||
|
||||
echo $jv
|
||||
echo $(( ~$jv ))
|
||||
echo $(( ~1 ))
|
||||
echo $(( ! 0 ))
|
||||
|
||||
echo $(( jv % 2 ))
|
||||
echo $(( $iv % 4 ))
|
||||
|
||||
echo $(( iv <<= 16 ))
|
||||
echo $(( iv %= 33 ))
|
||||
|
||||
echo $(( 33 & 55 ))
|
||||
echo $(( 33 | 17 ))
|
||||
|
||||
echo $(( iv && $jv ))
|
||||
echo $(( $iv || jv ))
|
||||
|
||||
echo $(( iv && 0 ))
|
||||
echo $(( iv & 0 ))
|
||||
echo $(( iv && 1 ))
|
||||
echo $(( iv & 1 ))
|
||||
|
||||
echo $(( $jv || 0 ))
|
||||
echo $(( jv | 0 ))
|
||||
echo $(( jv | 1 ))
|
||||
echo $(( $jv || 1 ))
|
||||
|
||||
let 'iv *= jv'
|
||||
echo $iv
|
||||
echo $jv
|
||||
let "jv += $iv"
|
||||
echo $jv
|
||||
|
||||
echo $(( jv /= iv ))
|
||||
echo $(( jv <<= 8 ))
|
||||
echo $(( jv >>= 4 ))
|
||||
|
||||
echo $(( iv |= 4 ))
|
||||
echo $(( iv &= 4 ))
|
||||
|
||||
echo $(( iv += (jv + 9)))
|
||||
echo $(( (iv + 4) % 7 ))
|
||||
|
||||
# unary plus, minus
|
||||
echo $(( +4 - 8 ))
|
||||
echo $(( -4 + 8 ))
|
||||
|
||||
# conditional expressions
|
||||
echo $(( 4<5 ? 1 : 32))
|
||||
echo $(( 4>5 ? 1 : 32))
|
||||
echo $(( 4>(2+3) ? 1 : 32))
|
||||
echo $(( 4<(2+3) ? 1 : 32))
|
||||
echo $(( (2+2)<(2+3) ? 1 : 32))
|
||||
echo $(( (2+2)>(2+3) ? 1 : 32))
|
||||
|
||||
# bug in bash versions through bash-3.2
|
||||
S=105
|
||||
W=$((S>99?4:S>9?3:S>0?2:0))
|
||||
echo $W
|
||||
unset W S
|
||||
|
||||
# check that the unevaluated part of the ternary operator does not do
|
||||
# evaluation or assignment
|
||||
x=i+=2
|
||||
y=j+=2
|
||||
declare -i i=1 j=1
|
||||
echo $((1 ? 20 : (x+=2)))
|
||||
echo $i,$x
|
||||
echo $((0 ? (y+=2) : 30))
|
||||
echo $j,$y
|
||||
|
||||
x=i+=2
|
||||
y=j+=2
|
||||
declare -i i=1 j=1
|
||||
echo $((1 ? 20 : (x+=2)))
|
||||
echo $i,$x
|
||||
echo $((0 ? (y+=2) : 30))
|
||||
echo $i,$y
|
||||
|
||||
# check precedence of assignment vs. conditional operator
|
||||
# should be an error
|
||||
declare -i x=2
|
||||
y=$((1 ? 20 : x+=2))
|
||||
|
||||
# check precedence of assignment vs. conditional operator
|
||||
declare -i x=2
|
||||
echo $((0 ? x+=2 : 20))
|
||||
|
||||
# associativity of assignment-operator operator
|
||||
declare -i i=1 j=2 k=3
|
||||
echo $((i += j += k))
|
||||
echo $i,$j,$k
|
||||
|
||||
# octal, hex
|
||||
echo $(( 0x100 | 007 ))
|
||||
echo $(( 0xff ))
|
||||
echo $(( 16#ff ))
|
||||
echo $(( 16#FF/2 ))
|
||||
echo $(( 8#44 ))
|
||||
|
||||
echo $(( 8 ^ 32 ))
|
||||
|
||||
# other bases
|
||||
echo $(( 16#a ))
|
||||
echo $(( 32#a ))
|
||||
echo $(( 56#a ))
|
||||
echo $(( 64#a ))
|
||||
|
||||
echo $(( 16#A ))
|
||||
echo $(( 32#A ))
|
||||
echo $(( 56#A ))
|
||||
echo $(( 64#A ))
|
||||
|
||||
echo $(( 64#@ ))
|
||||
echo $(( 64#_ ))
|
||||
|
||||
# weird bases
|
||||
echo $(( 3425#56 ))
|
||||
|
||||
# missing number after base
|
||||
echo $(( 2# ))
|
||||
|
||||
# these should generate errors
|
||||
echo $(( 7 = 43 ))
|
||||
echo $(( 2#44 ))
|
||||
echo $(( 44 / 0 ))
|
||||
let 'jv += $iv'
|
||||
echo $(( jv += \$iv ))
|
||||
let 'rv = 7 + (43 * 6'
|
||||
|
||||
# more errors
|
||||
declare -i i
|
||||
i=0#4
|
||||
i=2#110#11
|
||||
|
||||
((echo abc; echo def;); echo ghi)
|
||||
|
||||
if (((4+4) + (4 + 7))); then
|
||||
echo ok
|
||||
fi
|
||||
|
||||
(()) # make sure the null expression works OK
|
||||
|
||||
a=(0 2 4 6)
|
||||
echo $(( a[1] + a[2] ))
|
||||
echo $(( (a[1] + a[2]) == a[3] ))
|
||||
(( (a[1] + a[2]) == a[3] )) ; echo $?
|
||||
|
||||
# test pushing and popping the expression stack
|
||||
unset A
|
||||
A="4 + "
|
||||
echo $(( ( 4 + A ) + 4 ))
|
||||
A="3 + 5"
|
||||
echo $(( ( 4 + A ) + 4 ))
|
||||
|
||||
# badly-formed conditional expressions
|
||||
echo $(( 4 ? : $A ))
|
||||
echo $(( 1 ? 20 ))
|
||||
echo $(( 4 ? 20 : ))
|
||||
|
||||
# precedence and short-circuit evaluation
|
||||
B=9
|
||||
echo $B
|
||||
|
||||
echo $(( 0 && B=42 ))
|
||||
echo $B
|
||||
|
||||
echo $(( 1 || B=88 ))
|
||||
echo $B
|
||||
|
||||
echo $(( 0 && (B=42) ))
|
||||
echo $B
|
||||
|
||||
echo $(( (${$} - $$) && (B=42) ))
|
||||
echo $B
|
||||
|
||||
echo $(( 1 || (B=88) ))
|
||||
echo $B
|
||||
|
||||
# until command with (( )) command
|
||||
x=7
|
||||
|
||||
echo $x
|
||||
until (( x == 4 ))
|
||||
do
|
||||
echo $x
|
||||
x=4
|
||||
done
|
||||
|
||||
echo $x
|
||||
|
||||
# exponentiation
|
||||
echo $(( 2**15 - 1))
|
||||
echo $(( 2**(16-1)))
|
||||
echo $(( 2**16*2 ))
|
||||
echo $(( 2**31-1))
|
||||
echo $(( 2**0 ))
|
||||
|
||||
# {pre,post}-{inc,dec}rement and associated errors
|
||||
|
||||
x=4
|
||||
|
||||
echo $x
|
||||
echo $(( x++ ))
|
||||
echo $x
|
||||
echo $(( x-- ))
|
||||
echo $x
|
||||
|
||||
echo $(( --x ))
|
||||
echo $x
|
||||
|
||||
echo $(( ++x ))
|
||||
echo $x
|
||||
|
||||
echo $(( ++7 ))
|
||||
echo $(( 7-- ))
|
||||
|
||||
echo $(( --x=7 ))
|
||||
echo $(( ++x=7 ))
|
||||
|
||||
echo $(( x++=7 ))
|
||||
echo $(( x--=7 ))
|
||||
|
||||
echo $x
|
||||
|
||||
echo $(( +7 ))
|
||||
echo $(( -7 ))
|
||||
|
||||
echo $(( ++7 ))
|
||||
echo $(( --7 ))
|
||||
|
||||
${THIS_SH} ./arith1.sub
|
||||
${THIS_SH} ./arith2.sub
|
||||
${THIS_SH} ./arith3.sub
|
||||
|
||||
x=4
|
||||
y=7
|
||||
|
||||
(( x=8 , y=12 ))
|
||||
|
||||
echo $x $y
|
||||
|
||||
# should be an error
|
||||
(( x=9 y=41 ))
|
||||
|
||||
# These are errors
|
||||
unset b
|
||||
echo $((a b))
|
||||
((a b))
|
||||
|
||||
n=42
|
||||
printf "%d\n" $n
|
||||
printf "%i\n" $n
|
||||
echo $(( 8#$(printf "%o\n" $n) ))
|
||||
printf "%u\n" $n
|
||||
echo $(( 16#$(printf "%x\n" $n) ))
|
||||
echo $(( 16#$(printf "%X\n" $n) ))
|
||||
|
||||
# causes longjmp botches through bash-2.05b
|
||||
a[b[c]d]=e
|
||||
@@ -1,388 +0,0 @@
|
||||
# this is needed so that the bad assignments (b[]=bcde, for example) do not
|
||||
# cause fatal shell errors when in posix mode
|
||||
set +o posix
|
||||
|
||||
set +a
|
||||
# The calls to egrep -v are to filter out builtin array variables that are
|
||||
# automatically set and possibly contain values that vary.
|
||||
|
||||
# first make sure we handle the basics
|
||||
x=()
|
||||
echo ${x[@]}
|
||||
unset x
|
||||
|
||||
# this should be an error
|
||||
test=(first & second)
|
||||
echo $?
|
||||
unset test
|
||||
|
||||
# make sure declare -a converts an existing variable to an array
|
||||
unset a
|
||||
a=abcde
|
||||
declare -a a
|
||||
echo ${a[0]}
|
||||
|
||||
unset a
|
||||
a=abcde
|
||||
a[2]=bdef
|
||||
|
||||
unset b
|
||||
declare -a b[256]
|
||||
|
||||
unset c[2]
|
||||
unset c[*]
|
||||
|
||||
a[1]=
|
||||
|
||||
_ENV=/bin/true
|
||||
x=${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}
|
||||
|
||||
declare -r c[100]
|
||||
|
||||
echo ${a[0]} ${a[4]}
|
||||
echo ${a[@]}
|
||||
|
||||
echo ${a[*]}
|
||||
|
||||
# this should print out values, too
|
||||
declare -a | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
|
||||
unset a[7]
|
||||
echo ${a[*]}
|
||||
|
||||
unset a[4]
|
||||
echo ${a[*]}
|
||||
|
||||
echo ${a}
|
||||
echo "${a}"
|
||||
echo $a
|
||||
|
||||
unset a[0]
|
||||
echo ${a}
|
||||
|
||||
echo ${a[@]}
|
||||
|
||||
a[5]="hello world"
|
||||
echo ${a[5]}
|
||||
echo ${#a[5]}
|
||||
|
||||
echo ${#a[@]}
|
||||
|
||||
a[4+5/2]="test expression"
|
||||
declare a["7 + 8"]="test 2"
|
||||
a[7 + 8]="test 2"
|
||||
echo ${a[@]}
|
||||
|
||||
readonly a[5]
|
||||
readonly a
|
||||
# these two lines should output `declare' commands
|
||||
readonly -a | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
declare -ar | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
# this line should output `readonly' commands, even for arrays
|
||||
set -o posix
|
||||
readonly -a | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
set +o posix
|
||||
|
||||
declare -a d='([1]="" [2]="bdef" [5]="hello world" "test")'
|
||||
d[9]="ninth element"
|
||||
|
||||
declare -a e[10]=test # this works in post-bash-2.05 versions
|
||||
declare -a e[10]='(test)'
|
||||
|
||||
pass=/etc/passwd
|
||||
declare -a f='("${d[@]}")'
|
||||
b=([0]=this [1]=is [2]=a [3]=test [4]="$PS1" [5]=$pass)
|
||||
|
||||
echo ${b[@]:2:3}
|
||||
|
||||
declare -pa | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
|
||||
a[3]="this is a test"
|
||||
|
||||
b[]=bcde
|
||||
b[*]=aaa
|
||||
echo ${b[ ]}
|
||||
|
||||
c[-2]=4
|
||||
echo ${c[-4]}
|
||||
|
||||
d[7]=(abdedfegeee)
|
||||
|
||||
d=([]=abcde [1]="test test" [*]=last [-65]=negative )
|
||||
|
||||
unset d[12]
|
||||
unset e[*]
|
||||
|
||||
declare -a | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
|
||||
ps1='hello'
|
||||
unset ps1[2]
|
||||
unset ${ps1[2]}
|
||||
|
||||
declare +a ps1
|
||||
declare +a c
|
||||
|
||||
# the prompt should not print when using a here doc
|
||||
read -p "array test: " -a rv <<!
|
||||
this is a test of read using arrays
|
||||
!
|
||||
|
||||
echo ${rv[0]} ${rv[4]}
|
||||
echo ${rv[@]}
|
||||
|
||||
# the variable should be converted to an array when `read -a' is done
|
||||
vv=1
|
||||
read -a vv <<!
|
||||
this is a test of arrays
|
||||
!
|
||||
echo ${vv[0]} ${vv[3]}
|
||||
echo ${vv[@]}
|
||||
unset vv
|
||||
|
||||
declare -a | egrep -v '(BASH_VERSINFO|PIPESTATUS|GROUPS)'
|
||||
|
||||
export rv
|
||||
#set
|
||||
|
||||
x[4]=bbb
|
||||
x=abde
|
||||
echo $x
|
||||
echo ${x[0]}
|
||||
echo ${x[4]}
|
||||
echo efgh | ( read x[1] ; echo ${x[1]} )
|
||||
echo wxyz | ( declare -a x ; read x ; echo $x ; echo ${x[0]} )
|
||||
|
||||
# Make sure that arrays can be used to save the positional paramters verbatim
|
||||
set -- a 'b c' d 'e f g' h
|
||||
|
||||
ARGV=( [0]=$0 "$@" )
|
||||
|
||||
for z in "${ARGV[@]}"
|
||||
do
|
||||
echo "$z"
|
||||
done
|
||||
|
||||
echo "$0"
|
||||
for z in "$@"
|
||||
do
|
||||
echo "$z"
|
||||
done
|
||||
|
||||
# do various pattern removal and length tests
|
||||
XPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:.:/sbin:/usr/sbin
|
||||
|
||||
xpath=( $( IFS=: ; echo $XPATH ) )
|
||||
|
||||
echo ${xpath[@]}
|
||||
echo ${xpath[@]##*/}
|
||||
echo ${xpath[0]##*/}
|
||||
echo ${xpath[@]%%[!/]*}
|
||||
echo ${xpath[0]%%[!/]*}
|
||||
recho ${xpath##*/}
|
||||
recho ${xpath%%[!/]*}
|
||||
recho ${xpath[5]##*/}
|
||||
recho ${xpath[5]%%[!/]*}
|
||||
|
||||
# let's try to make it a DOS-style path
|
||||
|
||||
zecho "${xpath[@]/\//\\}"
|
||||
zecho "${xpath[@]//\//\\}"
|
||||
zecho "${xpath[@]//[\/]/\\}"
|
||||
|
||||
# length of the first element of the array, since array without subscript
|
||||
# is equivalent to referencing first element
|
||||
echo ${#xpath} -- ${#xpath[0]}
|
||||
|
||||
# number of elements in the array
|
||||
nelem=${#xpath[@]}
|
||||
echo ${#xpath[@]} -- $nelem
|
||||
|
||||
# total length of all elements in the array, including space separators
|
||||
xx="${xpath[*]}"
|
||||
echo ${#xx}
|
||||
|
||||
# total length of all elements in the array
|
||||
xx=$( IFS='' ; echo "${xpath[*]}" )
|
||||
echo ${#xx}
|
||||
|
||||
unset xpath[nelem-1]
|
||||
|
||||
nelem=${#xpath[@]}
|
||||
echo ${#xpath[@]} -- $nelem
|
||||
|
||||
# arrays and things that look like index assignments
|
||||
array=(42 [1]=14 [2]=44)
|
||||
|
||||
array2=(grep [ 123 ] \*)
|
||||
|
||||
echo ${array[@]}
|
||||
echo "${array2[@]}"
|
||||
|
||||
# arrays and implicit arithmetic evaluation
|
||||
declare -i -a iarray
|
||||
|
||||
iarray=( 2+4 1+6 7+2 )
|
||||
echo ${iarray[@]}
|
||||
|
||||
iarray[4]=4+1
|
||||
echo ${iarray[@]}
|
||||
|
||||
# make sure assignment using the compound assignment syntax removes all
|
||||
# of the old elements from the array value
|
||||
barray=(old1 old2 old3 old4 old5)
|
||||
barray=(new1 new2 new3)
|
||||
echo "length = ${#barray[@]}"
|
||||
echo "value = ${barray[*]}"
|
||||
|
||||
# make sure the array code behaves correctly with respect to unset variables
|
||||
set -u
|
||||
( echo ${#narray[4]} )
|
||||
|
||||
${THIS_SH} ./array1.sub
|
||||
${THIS_SH} ./array2.sub
|
||||
|
||||
# some old bugs and ksh93 compatibility tests
|
||||
${THIS_SH} ./array3.sub
|
||||
|
||||
# some compound assingment parsing problems that showed up in bash-3.1-release
|
||||
${THIS_SH} ./array4.sub
|
||||
|
||||
set +u
|
||||
cd /tmp
|
||||
|
||||
touch 1=bar
|
||||
foo=([10]="bar")
|
||||
echo ${foo[0]}
|
||||
rm 1=bar
|
||||
|
||||
cd $OLDPWD
|
||||
|
||||
foo=(a b c d e f g)
|
||||
echo ${foo[@]}
|
||||
|
||||
# quoted reserved words are ok
|
||||
foo=(\for \case \if \then \else)
|
||||
echo ${foo[@]}
|
||||
|
||||
# quoted metacharacters are ok
|
||||
foo=( [1]='<>' [2]='<' [3]='>' [4]='!' )
|
||||
echo ${foo[@]}
|
||||
|
||||
# numbers are just words when not in a redirection context
|
||||
foo=( 12 14 16 18 20 )
|
||||
echo ${foo[@]}
|
||||
|
||||
foo=( 4414758999202 )
|
||||
echo ${foo[@]}
|
||||
|
||||
# this was a bug in all versions of bash 2.x up to and including bash-2.04
|
||||
declare -a ddd=(aaa
|
||||
bbb)
|
||||
echo ${ddd[@]}
|
||||
|
||||
# errors until post-bash-2.05a; now reserved words are OK
|
||||
foo=(a b c for case if then else)
|
||||
|
||||
foo=(for case if then else)
|
||||
|
||||
# errors
|
||||
metas=( <> < > ! )
|
||||
metas=( [1]=<> [2]=< [3]=> [4]=! )
|
||||
|
||||
# various expansions that didn't really work right until post-bash-2.04
|
||||
foo='abc'
|
||||
echo ${foo[0]} ${#foo[0]}
|
||||
echo ${foo[1]} ${#foo[1]}
|
||||
echo ${foo[@]} ${#foo[@]}
|
||||
echo ${foo[*]} ${#foo[*]}
|
||||
|
||||
foo=''
|
||||
echo ${foo[0]} ${#foo[0]}
|
||||
echo ${foo[1]} ${#foo[1]}
|
||||
echo ${foo[@]} ${#foo[@]}
|
||||
echo ${foo[*]} ${#foo[*]}
|
||||
|
||||
# new expansions added after bash-2.05b
|
||||
x[0]=zero
|
||||
x[1]=one
|
||||
x[4]=four
|
||||
x[10]=ten
|
||||
|
||||
recho ${!x[@]}
|
||||
recho "${!x[@]}"
|
||||
recho ${!x[*]}
|
||||
recho "${!x[*]}"
|
||||
|
||||
# sparse array tests for code fixed in bash-3.0
|
||||
unset av
|
||||
av[1]='one'
|
||||
av[2]=''
|
||||
|
||||
av[3]=three
|
||||
av[5]=five
|
||||
av[7]=seven
|
||||
|
||||
echo include null element -- expect one
|
||||
echo ${av[@]:1:2} # what happens when we include a null element?
|
||||
echo include unset element -- expect three five
|
||||
echo ${av[@]:3:2} # what happens when we include an unset element?
|
||||
echo start at unset element -- expect five seven
|
||||
echo ${av[@]:4:2} # what happens when we start at an unset element?
|
||||
|
||||
echo too many elements -- expect three five seven
|
||||
echo ${av[@]:3:5} # how about too many elements?
|
||||
|
||||
echo positive offset - expect five seven
|
||||
echo ${av[@]:5:2}
|
||||
echo negative offset to unset element - expect seven
|
||||
echo ${av[@]: -2:2}
|
||||
|
||||
echo positive offset 2 - expect seven
|
||||
echo ${av[@]: 6:2}
|
||||
echo negative offset 2 - expect seven
|
||||
echo ${av[@]: -1:2}
|
||||
|
||||
echo out-of-range offset
|
||||
echo ${av[@]:12}
|
||||
|
||||
# parsing problems and other inconsistencies not fixed until post bash-3.0
|
||||
unset x
|
||||
declare -a x=(')' $$)
|
||||
[ ${x[1]} -eq $$ ] || echo bad
|
||||
|
||||
unset x
|
||||
declare -a x=(a b c d e)
|
||||
echo ${x[4]}
|
||||
|
||||
z=([1]=one [4]=four [7]=seven [10]=ten)
|
||||
|
||||
echo ${#z[@]}
|
||||
|
||||
echo ${!z[@]}
|
||||
|
||||
unset x
|
||||
declare -a x=(a \'b c\')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=(a 'b c')
|
||||
|
||||
echo "${x[1]}"
|
||||
|
||||
unset x
|
||||
declare -a x=($0)
|
||||
[ "${x[@]}" = $0 ] || echo double expansion of \$0
|
||||
declare -a x=(\$0)
|
||||
echo "${x[@]}"
|
||||
|
||||
# tests for bash-3.1 problems
|
||||
${THIS_SH} ./array5.sub
|
||||
|
||||
# tests for post-bash-3.2 problems, most fixed in bash-3.2 patches
|
||||
${THIS_SH} ./array6.sub
|
||||
${THIS_SH} ./array7.sub
|
||||
|
||||
${THIS_SH} ./array8.sub
|
||||
|
||||
${THIS_SH} ./array9.sub
|
||||
@@ -1,119 +0,0 @@
|
||||
echo ff{c,b,a}
|
||||
echo f{d,e,f}g
|
||||
echo {l,n,m}xyz
|
||||
echo {abc\,def}
|
||||
echo {abc}
|
||||
|
||||
echo \{a,b,c,d,e}
|
||||
echo {x,y,\{a,b,c}}
|
||||
echo {x\,y,\{abc\},trie}
|
||||
|
||||
echo /usr/{ucb/{ex,edit},lib/{ex,how_ex}}
|
||||
|
||||
echo XXXX\{`echo a b c | tr ' ' ','`\}
|
||||
eval echo XXXX\{`echo a b c | tr ' ' ','`\}
|
||||
|
||||
echo {}
|
||||
echo { }
|
||||
echo }
|
||||
echo {
|
||||
echo abcd{efgh
|
||||
|
||||
echo foo {1,2} bar
|
||||
echo `zecho foo {1,2} bar`
|
||||
echo $(zecho foo {1,2} bar)
|
||||
|
||||
var=baz
|
||||
varx=vx
|
||||
vary=vy
|
||||
|
||||
echo foo{bar,${var}.}
|
||||
echo foo{bar,${var}}
|
||||
|
||||
echo "${var}"{x,y}
|
||||
echo $var{x,y}
|
||||
echo ${var}{x,y}
|
||||
|
||||
unset var varx vary
|
||||
|
||||
# new sequence brace operators
|
||||
echo {1..10}
|
||||
|
||||
# this doesn't work yet
|
||||
echo {0..10,braces}
|
||||
# but this does
|
||||
echo {{0..10},braces}
|
||||
echo x{{0..10},braces}y
|
||||
|
||||
echo {3..3}
|
||||
echo x{3..3}y
|
||||
echo {10..1}
|
||||
echo {10..1}y
|
||||
echo x{10..1}y
|
||||
|
||||
echo {a..f}
|
||||
echo {f..a}
|
||||
|
||||
echo {a..A}
|
||||
echo {A..a}
|
||||
|
||||
echo {f..f}
|
||||
|
||||
# mixes are incorrectly-formed brace expansions
|
||||
echo {1..f}
|
||||
echo {f..1}
|
||||
|
||||
echo 0{1..9} {10..20}
|
||||
|
||||
# do negative numbers work?
|
||||
echo {-1..-10}
|
||||
echo {-20..0}
|
||||
|
||||
# weirdly-formed brace expansions -- fixed in post-bash-3.1
|
||||
echo a-{b{d,e}}-c
|
||||
|
||||
echo a-{bdef-{g,i}-c
|
||||
|
||||
echo {"klklkl"}{1,2,3}
|
||||
echo {"x,x"}
|
||||
|
||||
echo {1..10..2}
|
||||
echo {-1..-10..2}
|
||||
echo {-1..-10..-2}
|
||||
|
||||
echo {10..1..-2}
|
||||
echo {10..1..2}
|
||||
|
||||
echo {1..20..2}
|
||||
echo {1..20..20}
|
||||
|
||||
echo {100..0..5}
|
||||
echo {100..0..-5}
|
||||
|
||||
echo {a..z}
|
||||
echo {a..z..2}
|
||||
echo {z..a..-2}
|
||||
|
||||
# make sure brace expansion handles ints > 2**31 - 1 using intmax_t
|
||||
echo {2147483645..2147483649}
|
||||
|
||||
# unwanted zero-padding -- fixed post-bash-4.0
|
||||
echo {10..0..2}
|
||||
echo {10..0..-2}
|
||||
echo {-50..-0..5}
|
||||
|
||||
# bad
|
||||
echo {1..10.f}
|
||||
echo {1..ff}
|
||||
echo {1..10..ff}
|
||||
echo {1.20..2}
|
||||
echo {1..20..f2}
|
||||
echo {1..20..2f}
|
||||
echo {1..2f..2}
|
||||
echo {1..ff..2}
|
||||
echo {1..ff}
|
||||
echo {1..f}
|
||||
echo {1..0f}
|
||||
echo {1..10f}
|
||||
echo {1..10.f}
|
||||
echo {1..10.f}
|
||||
@@ -1,253 +0,0 @@
|
||||
# tests for miscellaneous builtins not tested elsewhere
|
||||
set +p
|
||||
set +o posix
|
||||
|
||||
ulimit -c 0 2>/dev/null
|
||||
|
||||
# check that break breaks loops
|
||||
for i in a b c; do echo $i; break; echo bad-$i; done
|
||||
echo end-1
|
||||
for i in a b c; do echo $i; break 1; echo bad-$i; done
|
||||
echo end-2
|
||||
for i in a b c; do
|
||||
for j in x y z; do
|
||||
echo $i:$j
|
||||
break
|
||||
echo bad-$i
|
||||
done
|
||||
echo end-$i
|
||||
done
|
||||
echo end-3
|
||||
|
||||
# check that break breaks nested loops
|
||||
for i in a b c; do
|
||||
for j in x y z; do
|
||||
echo $i:$j
|
||||
break 2
|
||||
echo bad-$i
|
||||
done
|
||||
echo end-$i
|
||||
done
|
||||
echo end
|
||||
|
||||
# check that continue continues loops
|
||||
for i in a b c; do echo $i; continue; echo bad-$i ; done
|
||||
echo end-1
|
||||
for i in a b c; do echo $i; continue 1; echo bad-$i; done
|
||||
echo end-2
|
||||
for i in a b c; do
|
||||
for j in x y z; do
|
||||
echo $i:$j
|
||||
continue
|
||||
echo bad-$i-$j
|
||||
done
|
||||
echo end-$i
|
||||
done
|
||||
echo end-3
|
||||
|
||||
# check that continue breaks out of nested loops
|
||||
for i in a b c; do
|
||||
for j in x y z; do
|
||||
echo $i:$j
|
||||
continue 2
|
||||
echo bad-$i-$j
|
||||
done
|
||||
echo end-$i
|
||||
done
|
||||
echo end
|
||||
|
||||
# check that `eval' re-evaluates arguments, but `builtin' and `command' do not
|
||||
AVAR='$BVAR'
|
||||
BVAR=foo
|
||||
|
||||
echo $AVAR
|
||||
builtin echo $AVAR
|
||||
command echo $AVAR
|
||||
eval echo \$AVAR
|
||||
eval echo $AVAR
|
||||
|
||||
# test out eval with a temp environment
|
||||
AVAR=bar eval echo \$AVAR
|
||||
BVAR=xxx eval echo $AVAR
|
||||
|
||||
unset -v AVAR BVAR
|
||||
|
||||
# test umask
|
||||
mask=$(umask)
|
||||
umask 022
|
||||
umask
|
||||
umask -S
|
||||
umask -S u=rwx,g=rwx,o=rx >/dev/null # 002
|
||||
umask
|
||||
umask -S
|
||||
umask -p
|
||||
umask -p -S
|
||||
umask 0
|
||||
umask -S
|
||||
umask ${mask} # restore original mask
|
||||
|
||||
# builtin/command without arguments should do nothing. maybe someday they will
|
||||
builtin
|
||||
command
|
||||
|
||||
# test enable
|
||||
enable -ps
|
||||
|
||||
enable -aps ; enable -nps
|
||||
|
||||
enable -n test
|
||||
case "$(type -t test)" in
|
||||
builtin) echo oops -- enable -n test failed ;;
|
||||
*) echo enable -n test worked ;;
|
||||
esac
|
||||
|
||||
enable test
|
||||
case "$(type -t test)" in
|
||||
builtin) echo enable test worked ;;
|
||||
*) echo oops -- enable test failed ;;
|
||||
esac
|
||||
|
||||
# test options to exec
|
||||
(exec -a specialname ${THIS_SH} -c 'echo $0' )
|
||||
(exec -l -a specialname ${THIS_SH} -c 'echo $0' )
|
||||
# test `clean' environment. if /bin/sh is bash, and the script version of
|
||||
# printenv is run, there will be variables in the environment that bash
|
||||
# sets on startup. Also test code that prefixes argv[0] with a dash.
|
||||
(export FOO=BAR ; exec -c -l printenv ) | grep FOO
|
||||
(FOO=BAR exec -c printenv ) | grep FOO
|
||||
|
||||
(export FOO=BAR ; exec printenv ) | grep FOO
|
||||
(FOO=BAR exec printenv ) | grep FOO
|
||||
|
||||
# ok, forget everything about hashed commands
|
||||
hash -r
|
||||
hash
|
||||
|
||||
# this had better succeed, since command -p guarantees we will find the
|
||||
# standard utilties
|
||||
command -p hash rm
|
||||
|
||||
# check out source/.
|
||||
|
||||
# sourcing a zero-length-file had better not be an error
|
||||
rm -f /tmp/zero-length-file
|
||||
cp /dev/null /tmp/zero-length-file
|
||||
. /tmp/zero-length-file
|
||||
echo $?
|
||||
rm /tmp/zero-length-file
|
||||
|
||||
AVAR=AVAR
|
||||
|
||||
. ./source1.sub
|
||||
AVAR=foo . ./source1.sub
|
||||
|
||||
. ./source2.sub
|
||||
echo $?
|
||||
|
||||
set -- a b c
|
||||
. ./source3.sub
|
||||
|
||||
# make sure source with arguments does not change the shell's positional
|
||||
# parameters, but that the sourced file sees the arguments as its
|
||||
# positional parameters
|
||||
echo "$@"
|
||||
. ./source3.sub x y z
|
||||
echo "$@"
|
||||
|
||||
# but if the sourced script sets the positional parameters explicitly, they
|
||||
# should be reflected in the calling shell's positional parameters. this
|
||||
# also tests one of the shopt options that controls source using $PATH to
|
||||
# find the script
|
||||
echo "$@"
|
||||
shopt -u sourcepath
|
||||
. source4.sub
|
||||
echo "$@"
|
||||
|
||||
# this is complicated when the sourced scripts gets its own positional
|
||||
# parameters from arguments to `.'
|
||||
set -- a b c
|
||||
echo "$@"
|
||||
. source4.sub x y z
|
||||
echo "$@"
|
||||
|
||||
# test out cd and $CDPATH
|
||||
${THIS_SH} ./builtins1.sub
|
||||
|
||||
# test behavior of `.' when given a non-existant file argument
|
||||
${THIS_SH} ./source5.sub
|
||||
|
||||
# test bugs in sourcing non-regular files, fixed post-bash-3.2
|
||||
${THIS_SH} ./source6.sub
|
||||
|
||||
# in posix mode, assignment statements preceding special builtins are
|
||||
# reflected in the shell environment. `.' and `eval' need special-case
|
||||
# code.
|
||||
set -o posix
|
||||
echo $AVAR
|
||||
AVAR=foo . ./source1.sub
|
||||
echo $AVAR
|
||||
|
||||
AVAR=AVAR
|
||||
echo $AVAR
|
||||
AVAR=foo eval echo \$AVAR
|
||||
echo $AVAR
|
||||
|
||||
AVAR=AVAR
|
||||
echo $AVAR
|
||||
AVAR=foo :
|
||||
echo $AVAR
|
||||
set +o posix
|
||||
|
||||
# but assignment statements preceding `export' are always reflected in
|
||||
# the environment
|
||||
foo="" export foo
|
||||
declare -p foo
|
||||
unset foo
|
||||
|
||||
# assignment statements preceding `declare' should be displayed correctly,
|
||||
# but not persist after the command
|
||||
FOO='$$' declare -p FOO
|
||||
declare -p FOO
|
||||
unset FOO
|
||||
|
||||
# except for `declare -x', which should be equivalent to `export'
|
||||
FOO='$$' declare -x FOO
|
||||
declare -p FOO
|
||||
unset FOO
|
||||
|
||||
# test out kill -l. bash versions prior to 2.01 did `kill -l num' wrong
|
||||
sigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
|
||||
|
||||
case "$(kill -l 1)" in
|
||||
${sigone/SIG/}) echo ok;;
|
||||
*) echo oops -- kill -l failure;;
|
||||
esac
|
||||
|
||||
# kill -l and trap -l should display exactly the same output
|
||||
sigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')
|
||||
|
||||
if [ "$sigone" != "$sigonea" ]; then
|
||||
echo oops -- kill -l and trap -l differ
|
||||
fi
|
||||
|
||||
# POSIX.2 says that exit statuses > 128 are mapped to signal names by
|
||||
# subtracting 128 so you can find out what signal killed a process
|
||||
case "$(kill -l $(( 128 + 1)) )" in
|
||||
${sigone/SIG/}) echo ok;;
|
||||
*) echo oops -- kill -l 129 failure;;
|
||||
esac
|
||||
|
||||
# out-of-range signal numbers should report the argument in the error
|
||||
# message, not 128 less than the argument
|
||||
kill -l 4096
|
||||
|
||||
# kill -l NAME should return the signal number
|
||||
kill -l ${sigone/SIG/}
|
||||
|
||||
# test behavior of shopt xpg_echo
|
||||
${THIS_SH} ./builtins2.sub
|
||||
|
||||
# this must be last -- it is a fatal error
|
||||
exit status
|
||||
|
||||
echo after bad exit
|
||||
@@ -1,211 +0,0 @@
|
||||
|
||||
# works right
|
||||
echo ab$(echo mnop)yz
|
||||
# works right
|
||||
echo ab$(echo mnop
|
||||
)yz
|
||||
#
|
||||
# works right
|
||||
echo $(echo ab
|
||||
)
|
||||
# works right
|
||||
echo $(
|
||||
)
|
||||
echo $()
|
||||
echo ab$()cd
|
||||
|
||||
echo $(case a in (a) echo sh_352.26ax; esac )
|
||||
echo $(case a in (a) echo sh_352.26ay; esac)
|
||||
|
||||
echo $((echo sh_352.25a);(echo sh_352.25b))
|
||||
|
||||
echo $(echo sh_352.27 ')' ")" \)
|
||||
# ) comment
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo abc # a comment with )
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<eof
|
||||
here doc with )
|
||||
eof
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo ')'
|
||||
)
|
||||
|
||||
unset x
|
||||
x=$(cat <<"EOF"
|
||||
bad' syntax
|
||||
EOF
|
||||
)
|
||||
echo "$x"
|
||||
unset x
|
||||
|
||||
echo $(for f in \); do echo a; done )
|
||||
echo $(case a in a) echo sh_352.26a; esac )
|
||||
echo $(case a in a) echo sh_352.26a; esac)
|
||||
|
||||
echo $(case a in
|
||||
(a) echo sh_352.26
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
echo $(case a in
|
||||
a) echo sh_352.26
|
||||
;;
|
||||
esac
|
||||
)
|
||||
|
||||
|
||||
echo $(case a in
|
||||
a) echo sh_352.26
|
||||
;;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
esac
|
||||
|
||||
)
|
||||
|
||||
echo $(( 4<(2+3) ? 1 : 32))
|
||||
|
||||
echo $(cat << end
|
||||
sh_352.28 )
|
||||
end
|
||||
)
|
||||
|
||||
echo $(cat <<- end
|
||||
sh_352.28 )
|
||||
end
|
||||
)
|
||||
|
||||
k=$(case x in x) echo k;; esac)
|
||||
echo $k
|
||||
|
||||
x=$(
|
||||
case $(ls) in
|
||||
example) echo foobix;;
|
||||
esac
|
||||
)
|
||||
|
||||
echo $( echo ab\
|
||||
cd)
|
||||
|
||||
echo `echo ab
|
||||
cd`
|
||||
|
||||
echo `echo ab #xyz
|
||||
cd`
|
||||
|
||||
echo "$(echo abcde)
|
||||
"
|
||||
|
||||
recho "$(echo abcde)
|
||||
"
|
||||
|
||||
echo $(echo abcde)\
|
||||
foo
|
||||
|
||||
recho $(echo abcde)\
|
||||
foo
|
||||
|
||||
recho "wx$(echo abcde)yz"
|
||||
recho "$(echo abcde)"
|
||||
|
||||
echo $(cat <<eof
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 1
|
||||
|
||||
echo $(cat <<\eof
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 2
|
||||
|
||||
echo "$(cat <<\eof
|
||||
'
|
||||
eof
|
||||
)"
|
||||
|
||||
echo after 3
|
||||
|
||||
echo "$(cat <<\eof
|
||||
`
|
||||
eof
|
||||
)"
|
||||
|
||||
echo after 4
|
||||
|
||||
echo $(
|
||||
cat << ')'
|
||||
hello
|
||||
)
|
||||
)
|
||||
|
||||
echo after 5
|
||||
|
||||
echo $(cat <<'eof'
|
||||
'
|
||||
eof
|
||||
)
|
||||
|
||||
echo after 6
|
||||
|
||||
echo $(
|
||||
case x in x) echo x;; esac
|
||||
)
|
||||
|
||||
echo $(
|
||||
case x in (x) echo x;; esac
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo 'quoted )'
|
||||
)
|
||||
|
||||
echo $(
|
||||
echo comment # with )
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\eof
|
||||
here-doc with )
|
||||
eof
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\)
|
||||
here-doc terminated with a parenthesis
|
||||
)
|
||||
)
|
||||
|
||||
echo $(
|
||||
cat <<\eof
|
||||
' # or a single back- or doublequote
|
||||
eof
|
||||
)
|
||||
|
||||
${THIS_SH} ./comsub-posix1.sub
|
||||
|
||||
${THIS_SH} ./comsub-posix2.sub
|
||||
|
||||
${THIS_SH} ./comsub-posix3.sub
|
||||
|
||||
# produced a parse error through bash-4.0-beta2
|
||||
: $(echo foo)"
|
||||
"
|
||||
|
||||
# fixed after bash-4.0 released
|
||||
: $(case a in a) echo ;; # comment
|
||||
esac)
|
||||
@@ -1,23 +0,0 @@
|
||||
# parsing errors before bash-4.2
|
||||
|
||||
a=$(/bin/cat << EOF | wc -l
|
||||
a
|
||||
b
|
||||
c
|
||||
EOF
|
||||
)
|
||||
|
||||
a=$(cat << EOF | wc -l
|
||||
a
|
||||
b
|
||||
c
|
||||
EOF
|
||||
)
|
||||
|
||||
a=$(/bin/cat << EOF
|
||||
a
|
||||
b
|
||||
c
|
||||
EOF
|
||||
| wc -l)
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
if [ $UID -eq 0 ]; then
|
||||
echo "execscript: the test suite should not be run as root" >&2
|
||||
fi
|
||||
|
||||
set -- one two three
|
||||
echo before exec1.sub: "$@"
|
||||
echo calling exec1.sub
|
||||
./exec1.sub aa bb cc dd ee
|
||||
echo after exec1.sub with args: $?
|
||||
./exec1.sub
|
||||
echo after exec1.sub without args: $?
|
||||
|
||||
# set up a fixed path so we know notthere will not be found
|
||||
PATH=/usr/bin:/bin:/usr/local/bin:
|
||||
export PATH
|
||||
|
||||
notthere
|
||||
echo $?
|
||||
|
||||
# this is iffy, since the error messages may vary from system to system
|
||||
# and /tmp might not exist
|
||||
ln -s ${THIS_SH} /tmp/bash 2>/dev/null
|
||||
if [ -f /tmp/bash ]; then
|
||||
/tmp/bash notthere
|
||||
else
|
||||
${THIS_SH} notthere
|
||||
fi
|
||||
echo $?
|
||||
rm -f /tmp/bash
|
||||
|
||||
# /bin/sh should be there on all systems
|
||||
${THIS_SH} /bin/sh
|
||||
echo $?
|
||||
|
||||
# try executing a directory
|
||||
/
|
||||
echo $?
|
||||
|
||||
${THIS_SH} /
|
||||
echo $?
|
||||
|
||||
# try sourcing a directory
|
||||
. /
|
||||
echo $?
|
||||
|
||||
# try sourcing a binary file -- post-2.04 versions don't do the binary file
|
||||
# check, and will probably fail with `command not found', or status 127
|
||||
# bash-4.1 and later check for 256 NUL characters and fail as binary files
|
||||
# if there are more than that, it's probably binary
|
||||
. ${THIS_SH} 2>/dev/null
|
||||
echo $?
|
||||
|
||||
# post-bash-2.05 versions allow sourcing non-regular files
|
||||
. /dev/null
|
||||
echo $?
|
||||
|
||||
# kill two birds with one test -- test out the BASH_ENV code
|
||||
echo echo this is bashenv > /tmp/bashenv
|
||||
export BASH_ENV=/tmp/bashenv
|
||||
${THIS_SH} ./exec3.sub
|
||||
rm -f /tmp/bashenv
|
||||
unset BASH_ENV
|
||||
|
||||
# we're resetting the $PATH to empty, so this should be last
|
||||
PATH=
|
||||
|
||||
notthere
|
||||
echo $?
|
||||
|
||||
command notthere
|
||||
echo $?
|
||||
|
||||
command -p notthere
|
||||
echo $?
|
||||
|
||||
# but -p should guarantee that we find all the standard utilities, even
|
||||
# with an empty or unset $PATH
|
||||
command -p sh -c 'echo this is $0'
|
||||
unset PATH
|
||||
command -p sh -c 'echo this is $0'
|
||||
|
||||
# a bug in bash before bash-2.01 caused PATH to be set to the empty string
|
||||
# when command -p was run with PATH unset
|
||||
echo ${PATH-unset}
|
||||
|
||||
echo "echo ok" | ${THIS_SH} -t
|
||||
|
||||
${THIS_SH} ./exec2.sub
|
||||
echo $?
|
||||
|
||||
${THIS_SH} ./exec4.sub
|
||||
|
||||
# try exec'ing a command that cannot be found in $PATH
|
||||
${THIS_SH} ./exec5.sub
|
||||
|
||||
# this was a bug in bash versions before bash-2.04
|
||||
${THIS_SH} -c 'cat </dev/null | cat >/dev/null' >&-
|
||||
|
||||
# checks for proper return values in subshell commands with inverted return
|
||||
# values
|
||||
|
||||
${THIS_SH} ./exec6.sub
|
||||
|
||||
# checks for properly deciding what constitutes an executable file
|
||||
${THIS_SH} ./exec7.sub
|
||||
|
||||
${THIS_SH} -i ./exec8.sub
|
||||
|
||||
true | `echo true` &
|
||||
|
||||
echo after
|
||||
|
||||
# Problem with bash at least back to version 3.0
|
||||
${THIS_SH} -c 'VAR=0; VAR=1 command exec; exit ${VAR}'
|
||||
|
||||
# problem with bash through bash-4.1
|
||||
(
|
||||
exec /var/empty/nosuch
|
||||
echo bad
|
||||
) 2>/dev/null
|
||||
[ $? = 127 ] || echo exit status = $? at $LINENO
|
||||
@@ -1,386 +0,0 @@
|
||||
#
|
||||
# A suite of tests for bash word expansions
|
||||
#
|
||||
# This tests parameter and variable expansion, with an empahsis on
|
||||
# proper quoting behavior.
|
||||
#
|
||||
# Chet Ramey
|
||||
|
||||
#
|
||||
# If you comment out the body of this function, you can do a diff against
|
||||
# `expansion-tests.right' to see if the shell is behaving correctly
|
||||
#
|
||||
expect()
|
||||
{
|
||||
echo expect "$@"
|
||||
}
|
||||
|
||||
# Test the substitution quoting characters (CTLESC and CTLNUL) in different
|
||||
# combinations
|
||||
|
||||
expect "<^A>"
|
||||
recho `echo ''`
|
||||
expect "<^A>"
|
||||
recho `echo ""`
|
||||
expect "<^B>"
|
||||
recho `echo ''`
|
||||
expect "<^B>"
|
||||
recho `echo ""`
|
||||
expect "<^A>"
|
||||
recho `echo `
|
||||
expect "<^B>"
|
||||
recho `echo `
|
||||
|
||||
# Test null strings without variable expansion
|
||||
expect "<abcdefgh>"
|
||||
recho abcd""efgh
|
||||
expect "<abcdefgh>"
|
||||
recho abcd''efgh
|
||||
expect "<abcdefgh>"
|
||||
recho ""abcdefgh
|
||||
expect "<abcdefgh>"
|
||||
recho ''abcdefgh
|
||||
expect "<abcd>"
|
||||
recho abcd""
|
||||
expect "<abcd>"
|
||||
recho abcd''
|
||||
|
||||
# Test the quirky behavior of $@ in ""
|
||||
expect nothing
|
||||
recho "$@"
|
||||
expect "< >"
|
||||
recho " $@"
|
||||
expect "<-->"
|
||||
recho "-${@}-"
|
||||
|
||||
# Test null strings with variable expansion that fails
|
||||
expect '<>'
|
||||
recho $xxx""
|
||||
expect '<>'
|
||||
recho ""$xxx
|
||||
expect '<>'
|
||||
recho $xxx''
|
||||
expect '<>'
|
||||
recho ''$xxx
|
||||
expect '<>'
|
||||
recho $xxx""$yyy
|
||||
expect '<>'
|
||||
recho $xxx''$yyy
|
||||
|
||||
# Test null strings with variable expansion that succeeds
|
||||
xxx=abc
|
||||
yyy=def
|
||||
|
||||
expect '<abc>'
|
||||
recho $xxx""
|
||||
expect '<abc>'
|
||||
recho ""$xxx
|
||||
expect '<abc>'
|
||||
recho $xxx''
|
||||
expect '<abc>'
|
||||
recho ''$xxx
|
||||
expect '<abcdef>'
|
||||
recho $xxx""$yyy
|
||||
expect '<abcdef>'
|
||||
recho $xxx''$yyy
|
||||
|
||||
unset xxx yyy
|
||||
|
||||
# Test the unquoted special quoting characters
|
||||
expect "<^A>"
|
||||
recho
|
||||
expect "<^B>"
|
||||
recho
|
||||
expect "<^A>"
|
||||
recho ""
|
||||
expect "<^B>"
|
||||
recho ""
|
||||
expect "<^A>"
|
||||
recho ''
|
||||
expect "<^B>"
|
||||
recho ''
|
||||
|
||||
# Test expansion of a variable that is unset
|
||||
expect nothing
|
||||
recho $xxx
|
||||
expect '<>'
|
||||
recho "$xxx"
|
||||
|
||||
expect nothing
|
||||
recho "$xxx${@}"
|
||||
|
||||
# Test empty string expansion
|
||||
expect '<>'
|
||||
recho ""
|
||||
expect '<>'
|
||||
recho ''
|
||||
|
||||
# Test command substitution with (disabled) history substitution
|
||||
expect '<Hello World!>'
|
||||
# set +H
|
||||
recho "`echo \"Hello world!\"`"
|
||||
|
||||
# Test some shell special characters
|
||||
expect '<`>'
|
||||
recho "\`"
|
||||
expect '<">'
|
||||
recho "\""
|
||||
expect '<\^A>'
|
||||
recho "\"
|
||||
|
||||
expect '<\$>'
|
||||
recho "\\$"
|
||||
|
||||
expect '<\\>'
|
||||
recho "\\\\"
|
||||
|
||||
# This should give argv[1] = a argv[2] = b
|
||||
expect '<a> <b>'
|
||||
FOO=`echo 'a b' | tr ' ' '\012'`
|
||||
recho $FOO
|
||||
|
||||
# This should give argv[1] = ^A argv[2] = ^B
|
||||
expect '<^A> <^B>'
|
||||
FOO=`echo ' ' | tr ' ' '\012'`
|
||||
recho $FOO
|
||||
|
||||
# Test quoted and unquoted globbing characters
|
||||
expect '<**>'
|
||||
recho "*"*
|
||||
|
||||
expect '<\.\./*/>'
|
||||
recho "\.\./*/"
|
||||
|
||||
# Test patterns that come up when the shell quotes funny character
|
||||
# combinations
|
||||
expect '<^A^B^A^B>'
|
||||
recho ''
|
||||
expect '<^A^A>'
|
||||
recho ''
|
||||
expect '<^A^B>'
|
||||
recho ''
|
||||
expect '<^A^A^B>'
|
||||
recho ''
|
||||
|
||||
# More tests of "$@"
|
||||
set abc def ghi jkl
|
||||
expect '< abc> <def> <ghi> <jkl >'
|
||||
recho " $@ "
|
||||
expect '< abc> <def> <ghi> <jkl >'
|
||||
recho "${1+ $@ }"
|
||||
|
||||
set abc def ghi jkl
|
||||
expect '<--abc> <def> <ghi> <jkl-->'
|
||||
recho "--$@--"
|
||||
|
||||
set "a b" cd ef gh
|
||||
expect '<a b> <cd> <ef> <gh>'
|
||||
recho ${1+"$@"}
|
||||
expect '<a b> <cd> <ef> <gh>'
|
||||
recho ${foo:-"$@"}
|
||||
expect '<a b> <cd> <ef> <gh>'
|
||||
recho "${@}"
|
||||
|
||||
expect '< >'
|
||||
recho " "
|
||||
expect '< - >'
|
||||
recho " - "
|
||||
|
||||
# Test combinations of different types of quoting in a fully-quoted string
|
||||
# (so the WHOLLY_QUOTED tests fail and it doesn't get set)
|
||||
expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
|
||||
recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
|
||||
|
||||
# Test the various Posix parameter expansions
|
||||
|
||||
expect '<foo bar>'
|
||||
recho "${x:-$(echo "foo bar")}"
|
||||
expect '<foo> <bar>'
|
||||
recho ${x:-$(echo "foo bar")}
|
||||
|
||||
unset X
|
||||
expect '<abc>'
|
||||
recho ${X:=abc}
|
||||
expect '<abc>'
|
||||
recho $X
|
||||
|
||||
set a b c
|
||||
expect '<posix>'
|
||||
recho ${3:+posix}
|
||||
|
||||
POSIX=/usr/posix
|
||||
expect '<10>'
|
||||
recho ${#POSIX}
|
||||
|
||||
# remove shortest trailing match
|
||||
x=file.c
|
||||
expect '<file.o>'
|
||||
recho ${x%.c}.o
|
||||
|
||||
# remove longest trailing match
|
||||
x=posix/src/std
|
||||
expect '<posix>'
|
||||
recho ${x%%/*}
|
||||
|
||||
# remove shortest leading pattern
|
||||
x=$HOME/src/cmd
|
||||
expect '</src/cmd>'
|
||||
recho ${x#$HOME}
|
||||
|
||||
# remove longest leading pattern
|
||||
x=/one/two/three
|
||||
expect '<three>'
|
||||
recho ${x##*/}
|
||||
|
||||
# pattern removal of patterns that don't match
|
||||
z=abcdef
|
||||
|
||||
expect '<abcdef>'
|
||||
recho ${z#xyz}
|
||||
expect '<abcdef>'
|
||||
recho ${z##xyz}
|
||||
|
||||
expect '<abcdef>'
|
||||
recho ${z%xyz}
|
||||
expect '<abcdef>'
|
||||
recho ${z%%xyz}
|
||||
|
||||
# Command substitution and the quirky differences between `` and $()
|
||||
|
||||
expect '<\$x>'
|
||||
recho '\$x'
|
||||
|
||||
expect '<$x>'
|
||||
recho `echo '\$x'`
|
||||
|
||||
expect '<\$x>'
|
||||
recho $(echo '\$x')
|
||||
|
||||
# The difference between $* "$*" and "$@"
|
||||
|
||||
set "abc" "def ghi" "jkl"
|
||||
|
||||
expect '<abc> <def> <ghi> <jkl>'
|
||||
recho $*
|
||||
|
||||
expect '<abc def ghi jkl>'
|
||||
recho "$*"
|
||||
|
||||
OIFS="$IFS"
|
||||
IFS=":$IFS"
|
||||
|
||||
# The special behavior of "$*", using the first character of $IFS as separator
|
||||
expect '<abc:def ghi:jkl>'
|
||||
recho "$*"
|
||||
|
||||
IFS="$OIFS"
|
||||
|
||||
expect '<abc> <def ghi> <jkl>'
|
||||
recho "$@"
|
||||
|
||||
expect '<xxabc> <def ghi> <jklyy>'
|
||||
recho "xx$@yy"
|
||||
|
||||
expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
|
||||
recho "$@$@"
|
||||
|
||||
foo=abc
|
||||
bar=def
|
||||
|
||||
expect '<abcdef>'
|
||||
recho "$foo""$bar"
|
||||
|
||||
unset foo
|
||||
set $foo bar '' xyz "$foo" abc
|
||||
|
||||
expect '<bar> <> <xyz> <> <abc>'
|
||||
recho "$@"
|
||||
|
||||
# More tests of quoting and deferred evaluation
|
||||
|
||||
foo=10 x=foo
|
||||
y='$'$x
|
||||
expect '<$foo>'
|
||||
recho $y
|
||||
eval y='$'$x
|
||||
expect '<10>'
|
||||
recho $y
|
||||
|
||||
# case statements
|
||||
|
||||
NL='
|
||||
'
|
||||
x='ab
|
||||
cd'
|
||||
|
||||
expect '<newline expected>'
|
||||
case "$x" in
|
||||
*$NL*) recho "newline expected" ;;
|
||||
esac
|
||||
|
||||
expect '<got it>'
|
||||
case \? in
|
||||
*"?"*) recho "got it" ;;
|
||||
esac
|
||||
|
||||
expect '<got it>'
|
||||
case \? in
|
||||
*\?*) recho "got it" ;;
|
||||
esac
|
||||
|
||||
set one two three four five
|
||||
expect '<one> <three> <five>'
|
||||
recho $1 $3 ${5} $8 ${9}
|
||||
|
||||
# length tests on positional parameters and some special parameters
|
||||
|
||||
expect '<5> <5>'
|
||||
recho $# ${#}
|
||||
expect '<3>'
|
||||
recho ${#1}
|
||||
expect '<1>'
|
||||
recho ${##}
|
||||
expect '<1>'
|
||||
recho ${#?}
|
||||
expect '<5>'
|
||||
recho ${#@}
|
||||
expect '<5>'
|
||||
recho ${#*}
|
||||
expect '<5>'
|
||||
recho "${#@}"
|
||||
expect '<5>'
|
||||
recho "${#*}"
|
||||
|
||||
expect '<42>'
|
||||
recho $((28 + 14))
|
||||
expect '<26>'
|
||||
recho $[ 13 * 2 ]
|
||||
|
||||
expect '<\>'
|
||||
recho `echo \\\\`
|
||||
|
||||
expect '<~>'
|
||||
recho '~'
|
||||
|
||||
expect nothing
|
||||
recho $!
|
||||
expect nothing
|
||||
recho ${!}
|
||||
|
||||
# test word splitting of assignment statements not preceding a command
|
||||
a="a b c d e"
|
||||
declare b=$a
|
||||
expect '<a> <b> <c> <d> <e>'
|
||||
recho $b
|
||||
|
||||
a="a?b?c"
|
||||
|
||||
echo ${a//\\?/ }
|
||||
|
||||
echo ${a//\?/ }
|
||||
|
||||
${THIS_SH} ./exp1.sub
|
||||
|
||||
${THIS_SH} ./exp2.sub
|
||||
|
||||
${THIS_SH} ./exp3.sub
|
||||
@@ -1,176 +0,0 @@
|
||||
a()
|
||||
{
|
||||
x=$((x - 1))
|
||||
return 5
|
||||
}
|
||||
|
||||
b()
|
||||
{
|
||||
x=$((x - 1))
|
||||
a
|
||||
echo a returns $?
|
||||
return 4
|
||||
}
|
||||
|
||||
c()
|
||||
{
|
||||
x=$((x - 1))
|
||||
b
|
||||
echo b returns $?
|
||||
return 3
|
||||
}
|
||||
|
||||
d()
|
||||
{
|
||||
x=$((x - 1))
|
||||
c
|
||||
echo c returns $?
|
||||
return 2
|
||||
}
|
||||
|
||||
e()
|
||||
{
|
||||
d
|
||||
echo d returns $?
|
||||
echo in e
|
||||
x=$((x - 1))
|
||||
return $x
|
||||
}
|
||||
|
||||
f()
|
||||
{
|
||||
e
|
||||
echo e returned $?
|
||||
echo x is $x
|
||||
return 0
|
||||
}
|
||||
|
||||
x=30
|
||||
f
|
||||
|
||||
# make sure unsetting a local variable preserves the `local' attribute
|
||||
f1()
|
||||
{
|
||||
local zz
|
||||
zz=abcde
|
||||
echo $zz
|
||||
unset zz
|
||||
zz=defghi
|
||||
echo $zz
|
||||
}
|
||||
|
||||
zz=ZZ
|
||||
echo $zz
|
||||
f1
|
||||
echo $zz
|
||||
|
||||
unset -f f1
|
||||
f1()
|
||||
{
|
||||
return 5
|
||||
}
|
||||
|
||||
( f1 )
|
||||
echo $?
|
||||
|
||||
unset -f f1
|
||||
f1()
|
||||
{
|
||||
sleep 5
|
||||
return 5
|
||||
}
|
||||
|
||||
f1 &
|
||||
wait
|
||||
echo $?
|
||||
|
||||
unset -f f1
|
||||
|
||||
f1()
|
||||
{
|
||||
echo $AVAR
|
||||
printenv AVAR
|
||||
}
|
||||
|
||||
AVAR=AVAR
|
||||
echo $AVAR
|
||||
f1
|
||||
AVAR=foo f1
|
||||
echo $AVAR
|
||||
|
||||
unset -f f1
|
||||
# make sure subshells can do a `return' if we're executing in a function
|
||||
f1()
|
||||
{
|
||||
( return 5 )
|
||||
status=$?
|
||||
echo $status
|
||||
return $status
|
||||
}
|
||||
|
||||
f1
|
||||
echo $?
|
||||
|
||||
declare -F f1 # should print just the name
|
||||
declare -f f1 # should print the definition, too
|
||||
|
||||
# no functions should be exported, right?
|
||||
declare -xF
|
||||
declare -xf
|
||||
|
||||
# FUNCNAME tests
|
||||
func2()
|
||||
{
|
||||
echo FUNCNAME = $FUNCNAME
|
||||
}
|
||||
|
||||
func()
|
||||
{
|
||||
echo before: FUNCNAME = $FUNCNAME
|
||||
func2
|
||||
echo after: FUNCNAME = $FUNCNAME
|
||||
}
|
||||
|
||||
echo before: try to assign to FUNCNAME
|
||||
FUNCNAME=7
|
||||
|
||||
echo outside: FUNCNAME = $FUNCNAME
|
||||
func
|
||||
echo outside2: FUNCNAME = $FUNCNAME
|
||||
|
||||
# test exported functions (and cached exportstr)
|
||||
zf()
|
||||
{
|
||||
echo this is zf
|
||||
}
|
||||
export -f zf
|
||||
|
||||
${THIS_SH} -c 'type -t zf'
|
||||
${THIS_SH} -c 'type zf'
|
||||
|
||||
${THIS_SH} ./func1.sub
|
||||
|
||||
# tests for functions whose bodies are not group commands, with and without
|
||||
# attached redirections
|
||||
${THIS_SH} ./func2.sub
|
||||
|
||||
# test for some posix-specific function behavior
|
||||
${THIS_SH} ./func3.sub
|
||||
|
||||
unset -f myfunction
|
||||
myfunction() {
|
||||
echo "bad shell function redirection"
|
||||
} >> /dev/null
|
||||
|
||||
myfunction
|
||||
myfunction | cat
|
||||
|
||||
segv()
|
||||
{
|
||||
echo foo | return 5
|
||||
}
|
||||
|
||||
segv
|
||||
echo $?
|
||||
|
||||
exit 0
|
||||
@@ -1,126 +0,0 @@
|
||||
LC_ALL=C
|
||||
LANG=C
|
||||
trap 'rm /tmp/newhistory' 0
|
||||
|
||||
file=bax
|
||||
histchars='!^#' # make sure history comment char is set correctly
|
||||
|
||||
unset HISTFILESIZE
|
||||
|
||||
history -c
|
||||
|
||||
HISTFILE=history.list
|
||||
HISTCONTROL=ignoreboth
|
||||
HISTIGNORE='&:#*:history*:fc*'
|
||||
# we will end up exercising the history stifling code as a result
|
||||
HISTSIZE=32
|
||||
|
||||
shopt -s cmdhist
|
||||
set -o history
|
||||
|
||||
history -p '!!'
|
||||
|
||||
# this should result in a failed history expansion error
|
||||
history -p '!!:z'
|
||||
|
||||
history
|
||||
|
||||
HISTFILE=/tmp/newhistory
|
||||
history -a
|
||||
|
||||
history -w
|
||||
|
||||
history -s "echo line 2 for history"
|
||||
history
|
||||
history -p '!e'
|
||||
history -p '!!'
|
||||
|
||||
set -H
|
||||
!!
|
||||
!e
|
||||
|
||||
history
|
||||
|
||||
echo a b c d e
|
||||
!?ch?
|
||||
!-2
|
||||
^2^8
|
||||
|
||||
!2
|
||||
|
||||
# we're selecting /bin/sh -c ...; we want `sh'
|
||||
echo !-1:0:t
|
||||
# we're selecting /bin/sh -c ...; we want `/bin'
|
||||
echo !-2:0:h
|
||||
# we're selecting `echo a b c d e'; we want `e'
|
||||
echo !?d?:5
|
||||
|
||||
echo a b c d e
|
||||
echo !-1:2-$
|
||||
echo !-2:2-4
|
||||
echo !-2:3*
|
||||
echo !!:*
|
||||
|
||||
echo !?a?:2-
|
||||
|
||||
echo file.c
|
||||
echo !!:$:r
|
||||
echo !-2:$:e
|
||||
echo !-3:$:r:q
|
||||
|
||||
echo $file.c
|
||||
echo !!:$:r
|
||||
echo !-2:^:e
|
||||
echo !-3:$:r:q
|
||||
|
||||
echo a b c d e
|
||||
echo !!:1-$:x
|
||||
echo !-2:1-$:q
|
||||
|
||||
echo foo.c foo.o foo.html foo.h
|
||||
!!:s/foo/bar/
|
||||
!-2:gs/foo/bar/
|
||||
!!:gs/bar/x&/
|
||||
!-2:g&
|
||||
|
||||
# make sure we can use any delimiter in the substitution, not just `/'
|
||||
!!:gs+bar+whix+
|
||||
|
||||
!!:p
|
||||
|
||||
# wow
|
||||
echo !?.o?:%:r:q
|
||||
|
||||
!!:0 !?.h?:%:q
|
||||
!!:-$
|
||||
!:-$
|
||||
|
||||
history
|
||||
|
||||
# make sure single quotes inhibit history expansion
|
||||
echo '!!'
|
||||
|
||||
# make sure backslashes can quote the history expansion character
|
||||
echo \!\!
|
||||
|
||||
# but other expansions on the line should still be processed
|
||||
|
||||
echo '!!' !!:*
|
||||
history -c
|
||||
unset HISTFILE
|
||||
|
||||
# make sure that the special bash cases are not history expanded
|
||||
case p in
|
||||
[!A-Z]) echo ok 1;;
|
||||
esac
|
||||
|
||||
var1='ok 2'
|
||||
var2=var1
|
||||
|
||||
echo ${!var2}
|
||||
|
||||
echo & echo $!; echo after
|
||||
|
||||
# Bash-2.01[.1] fails this test -- it attempts history expansion after the
|
||||
# history_comment_char
|
||||
echo ok 3 # !1200
|
||||
@@ -1,41 +0,0 @@
|
||||
export LC_ALL=en_US.UTF-8
|
||||
|
||||
a=$'\303\251'
|
||||
|
||||
echo "$a"
|
||||
|
||||
echo ${#a}
|
||||
|
||||
b=$'A\303\251B'
|
||||
|
||||
echo "$b"
|
||||
|
||||
echo ${b: -1}
|
||||
|
||||
c=AeB
|
||||
|
||||
echo ${c: -1}
|
||||
|
||||
unset a
|
||||
a=$(printf '%b' 'A\303\251B')
|
||||
IFS=$(printf '%b' '\303\251')
|
||||
|
||||
case "$a" in
|
||||
"A${IFS}B") echo ok 1 ;;
|
||||
*) echo bad 1 ;;
|
||||
esac
|
||||
|
||||
set $a
|
||||
|
||||
case $1 in
|
||||
A) echo ok 2 ;;
|
||||
*) echo bad 2 ;;
|
||||
esac
|
||||
|
||||
set a b
|
||||
|
||||
printf '%s\n' "$*"
|
||||
printf '%s' "$*" | od -b
|
||||
|
||||
# display differences make this problematic
|
||||
${THIS_SH} ./intl1.sub
|
||||
@@ -1,37 +0,0 @@
|
||||
shopt -s lastpipe
|
||||
|
||||
unset foo bar
|
||||
echo a b c | read foo
|
||||
echo after 1: foo = $foo
|
||||
|
||||
unset tot
|
||||
declare -i tot
|
||||
printf "%d\n" 1 2 3 | while read foo; do tot+=$foo; done
|
||||
echo after 2: tot = $tot
|
||||
|
||||
unset bar
|
||||
echo g h i | bar=7
|
||||
echo after: $bar
|
||||
|
||||
unset foo last
|
||||
printf "%s\n" a b c | while read foo; do last=$foo; done
|
||||
echo last = $last
|
||||
|
||||
exit 142 | false
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
|
||||
true | false | /usr/bin/true
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
|
||||
true | /usr/bin/true | false
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
|
||||
set -o pipefail
|
||||
true | /usr/bin/true | false
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
|
||||
true | /usr/bin/false | true
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
set +o pipefail
|
||||
|
||||
${THIS_SH} ./lastpipe1.sub
|
||||
@@ -1,4 +0,0 @@
|
||||
# with lastpipe set, exit at the end of a pipeline exits
|
||||
# the calling shell
|
||||
exit 142 | exit 14
|
||||
echo after: $?
|
||||
@@ -1,50 +0,0 @@
|
||||
:; ./shx
|
||||
|
||||
sh:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:00 EDT 1992
|
||||
bang geoff
|
||||
quote 712824302
|
||||
setbq defmsgid=<1992Aug3.024502.6176@host>
|
||||
bgwait sleep done... wait 6187
|
||||
|
||||
|
||||
bash:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:09 EDT 1992
|
||||
bang geoff
|
||||
quote 712824311
|
||||
setbq defmsgid=<1992Aug3.024512.6212@host>
|
||||
bgwait sleep done... wait 6223
|
||||
|
||||
|
||||
ash:
|
||||
<&$fd shx1: 4: Syntax error: Bad fd number
|
||||
nlbq Mon Aug 3 02:45:19 EDT 1992
|
||||
bang geoff
|
||||
quote getdate: `"now"' not a valid date
|
||||
|
||||
setbq defmsgid=<1992Aug3.` echo 024521
|
||||
bgwait sleep done... wait 6241
|
||||
|
||||
|
||||
ksh:
|
||||
<&$fd ok
|
||||
nlbq ./shx: 6248 Memory fault - core dumped
|
||||
bang geoff
|
||||
quote getdate: `"now"' not a valid date
|
||||
|
||||
setbq defmsgid=<1992Aug3.024530.6257@host>
|
||||
bgwait no such job: 6265
|
||||
wait 6265
|
||||
sleep done...
|
||||
|
||||
zsh:
|
||||
<&$fd ok
|
||||
nlbq Mon Aug 3 02:45:36 EDT 1992
|
||||
bang shx3: event not found: /s/ [4]
|
||||
quote 712824337
|
||||
setbq defmsgid=<..6290@host>
|
||||
bgwait shx7: unmatched " [9]
|
||||
sleep done...
|
||||
:;
|
||||
@@ -1,10 +0,0 @@
|
||||
#! /bin/sh
|
||||
for cmd in sh bash ash ksh zsh
|
||||
do
|
||||
echo
|
||||
echo $cmd:
|
||||
for demo in shx?
|
||||
do
|
||||
$cmd $demo
|
||||
done
|
||||
done
|
||||
@@ -1,578 +0,0 @@
|
||||
# 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
|
||||
|
||||
# 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"}
|
||||
@@ -1,76 +0,0 @@
|
||||
unset a
|
||||
printf "%s\n" ${a:=a\ b}
|
||||
echo "$a"
|
||||
|
||||
unset v
|
||||
recho ${v=a\ b} x ${v=c\ d}
|
||||
|
||||
unset v
|
||||
recho "${v=a\ b}" x "${v=c\ d}"
|
||||
|
||||
unset a v
|
||||
|
||||
recho "foo ${IFS+'bar'} baz"
|
||||
recho "a ${IFS+b c} d"
|
||||
|
||||
recho "a ${IFS+"b c"} d"
|
||||
|
||||
u=x
|
||||
recho "foo ${IFS+a$u{{{\}b} c ${IFS+d{}} bar" ${IFS-e{}} baz
|
||||
|
||||
a=foo
|
||||
recho "${IFS+'$a'}"
|
||||
recho "${IFS+"'$a'"}"
|
||||
|
||||
recho ${IFS+'$a'}
|
||||
recho ${IFS+"'$a'"}
|
||||
|
||||
unset a u
|
||||
x='foo*bar'
|
||||
|
||||
recho "${x##"}"}"
|
||||
recho "${x##'}'}"
|
||||
recho "${x##'}"
|
||||
|
||||
recho "${x:-'}'}"
|
||||
|
||||
foo="x'a'y"
|
||||
recho "${foo%*'a'*}"
|
||||
unset x
|
||||
|
||||
unset u
|
||||
v=w
|
||||
printf '<%s> ' ${u+x} . ${v+x} . "${u+x}" . "${v+x}" .; echo
|
||||
printf '<%s> ' ${u-x} . ${v-x} . "${u-x}" . "${v-x}" .; echo
|
||||
printf '<%s> ' ${u=x} . ${v=x} . "${u=x}" . "${v=x}" .; echo
|
||||
printf '<%s> ' ${u?x} . ${v?x} . "${u?x}" . "${v?x}" .; echo
|
||||
printf '<%s> ' ${u#x} . ${v#x} . "${u#x}" . "${v#x}" .; echo
|
||||
printf '<%s> ' ${u%x} . ${v%x} . "${u%x}" . "${v%x}" .; echo
|
||||
printf '<%s> ' ${u:+x} . ${v:+x} . "${u:+x}" . "${v:+x}" .; echo
|
||||
printf '<%s> ' ${u:-x} . ${v:-x} . "${u:-x}" . "${v:-x}" .; echo
|
||||
printf '<%s> ' ${u:=x} . ${v:=x} . "${u:=x}" . "${v:=x}" .; echo
|
||||
printf '<%s> ' ${u:?x} . ${v:?x} . "${u:?x}" . "${v:?x}" .; echo
|
||||
# these are invalid substitution operators
|
||||
#printf '<%s> ' ${u:#x} . ${v:#x} . "${u:#x}" . "${v:#x}" .; echo
|
||||
#printf '<%s> ' ${u:%x} . ${v:%x} . "${u:%x}" . "${v:%x}" .; echo
|
||||
|
||||
unset foo
|
||||
set -o posix
|
||||
|
||||
recho "${IFS+'bar}"
|
||||
recho "foo ${IFS+'bar} baz"
|
||||
|
||||
recho ${IFS+'}'z}
|
||||
recho "${IFS+'}'z}"
|
||||
|
||||
: ${TMPDIR:=/var/tmp}
|
||||
rm -f $TMPDIR/sh
|
||||
cp ${THIS_SH} $TMPDIR/sh
|
||||
THIS_SH=$TMPDIR/sh ${THIS_SH} ./posixexp1.sub || echo "sh posixexp1.sub: test $? failed"
|
||||
${THIS_SH} ./posixexp1.sub || echo "bash posixexp1.sub: test $? failed"
|
||||
|
||||
rm -f $TMPDIR/sh
|
||||
|
||||
# this will be an error
|
||||
foo=bar
|
||||
echo "${foo:-"a}"
|
||||
@@ -1,30 +0,0 @@
|
||||
# $FreeBSD: src/tools/regression/bin/sh/expansion/set-u1.0,v 1.2 2010/10/12 18:20:38 obrien Exp $
|
||||
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo}' 2>/dev/null && exit 1
|
||||
${THIS_SH} -uc 'unset foo; echo $foo' 2>/dev/null && exit 1
|
||||
${THIS_SH} -uc 'foo=; echo $foo' >/dev/null || exit 2
|
||||
${THIS_SH} -uc 'foo=1; echo $foo' >/dev/null || exit 3
|
||||
# -/+/= are unaffected by set -u
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo-}' >/dev/null || exit 4
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo+}' >/dev/null || exit 5
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo=}' >/dev/null || exit 6
|
||||
# length/trimming are affected
|
||||
${THIS_SH} -uc 'unset foo; echo ${#foo}' 2>/dev/null && exit 7
|
||||
${THIS_SH} -uc 'foo=; echo ${#foo}' >/dev/null || exit 8
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo#?}' 2>/dev/null && exit 9
|
||||
${THIS_SH} -uc 'foo=1; echo ${foo#?}' >/dev/null || exit 10
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo##?}' 2>/dev/null && exit 11
|
||||
${THIS_SH} -uc 'foo=1; echo ${foo##?}' >/dev/null || exit 12
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo%?}' 2>/dev/null && exit 13
|
||||
${THIS_SH} -uc 'foo=1; echo ${foo%?}' >/dev/null || exit 14
|
||||
${THIS_SH} -uc 'unset foo; echo ${foo%%?}' 2>/dev/null && exit 15
|
||||
${THIS_SH} -uc 'foo=1; echo ${foo%%?}' >/dev/null || exit 16
|
||||
|
||||
${THIS_SH} -uc 'echo $!' 2>/dev/null && exit 17
|
||||
${THIS_SH} -uc ':& echo $!' >/dev/null || exit 18
|
||||
${THIS_SH} -uc 'echo $#' >/dev/null || exit 19
|
||||
${THIS_SH} -uc 'echo $1' 2>/dev/null && exit 20
|
||||
${THIS_SH} -uc 'echo $1' ${THIS_SH} x >/dev/null || exit 21
|
||||
${THIS_SH} -uc 'echo $2' ${THIS_SH} x 2>/dev/null && exit 22
|
||||
${THIS_SH} -uc 'echo $2' ${THIS_SH} x y >/dev/null || exit 23
|
||||
exit 0
|
||||
@@ -1,41 +0,0 @@
|
||||
# Test timed and negated pipelines in bash-4.2 and later
|
||||
export TIMEFORMAT=$'real %2R\nuser %2U\nsys %2S'
|
||||
|
||||
!
|
||||
echo $?
|
||||
|
||||
! !
|
||||
echo $?
|
||||
|
||||
time ! echo a
|
||||
echo $?
|
||||
|
||||
! time echo a
|
||||
echo $?
|
||||
|
||||
tfunc()
|
||||
{
|
||||
time
|
||||
}
|
||||
|
||||
type tfunc
|
||||
|
||||
! true
|
||||
echo $?
|
||||
! ! true
|
||||
echo $?
|
||||
! ! ! true
|
||||
echo $?
|
||||
|
||||
time time echo a
|
||||
echo $?
|
||||
|
||||
time time -p echo a
|
||||
echo $?
|
||||
time -p time echo a
|
||||
echo $?
|
||||
|
||||
!
|
||||
echo $?
|
||||
! !
|
||||
echo $?
|
||||
@@ -1,313 +0,0 @@
|
||||
LC_ALL=C
|
||||
LC_NUMERIC=C
|
||||
|
||||
# these should output error messages -- the format is required
|
||||
printf
|
||||
printf --
|
||||
|
||||
# these should output nothing
|
||||
printf ""
|
||||
printf -- ""
|
||||
|
||||
# in the future this may mean to put the output into VAR, but for
|
||||
# now it is an error
|
||||
# 2005-03-15 no longer an error
|
||||
unset var
|
||||
printf -v var "%10d" $RANDOM
|
||||
echo ${#var}
|
||||
|
||||
# this should expand escape sequences in the format string, nothing else
|
||||
printf "\tone\n"
|
||||
|
||||
# this should not cut off output after the \c
|
||||
printf "one\ctwo\n"
|
||||
|
||||
# and unrecognized backslash escapes should have the backslash preserverd
|
||||
printf "4\.2\n"
|
||||
|
||||
printf "no newline " ; printf "now newline\n"
|
||||
|
||||
# %% -> %
|
||||
printf "%%\n"
|
||||
|
||||
# this was a bug caused by pre-processing the string for backslash escapes
|
||||
# before doing the `%' format processing -- all versions before bash-2.04
|
||||
printf "\045" ; echo
|
||||
printf "\045d\n"
|
||||
|
||||
# simple character output
|
||||
printf "%c\n" ABCD
|
||||
|
||||
# test simple string output
|
||||
printf "%s\n" unquoted
|
||||
|
||||
# test quoted string output
|
||||
printf "%s %q\n" unquoted quoted
|
||||
printf "%s%10q\n" unquoted quoted
|
||||
|
||||
printf "%q\n" 'this&that'
|
||||
|
||||
# make sure the format string is reused to use up arguments
|
||||
printf "%d " 1 2 3 4 5; printf "\n"
|
||||
|
||||
# make sure that extra format characters get null arguments
|
||||
printf "%s %d %d %d\n" onestring
|
||||
|
||||
printf "%s %d %u %4.2f\n" onestring
|
||||
|
||||
printf -- "--%s %s--\n" 4.2 ''
|
||||
printf -- "--%s %s--\n" 4.2
|
||||
|
||||
# test %b escapes
|
||||
|
||||
# 8 is a non-octal digit, so the `81' should be output
|
||||
printf -- "--%b--\n" '\n\081'
|
||||
|
||||
printf -- "--%b--\n" '\t\0101'
|
||||
printf -- "--%b--\n" '\t\101'
|
||||
|
||||
# these should all display `A7'
|
||||
echo -e "\01017"
|
||||
echo -e "\x417"
|
||||
|
||||
printf "%b\n" '\01017'
|
||||
printf "%b\n" '\1017'
|
||||
printf "%b\n" '\x417'
|
||||
|
||||
printf -- "--%b--\n" '\"abcd\"'
|
||||
printf -- "--%b--\n" "\'abcd\'"
|
||||
|
||||
printf -- "--%b--\n" 'a\\x'
|
||||
|
||||
printf -- "--%b--\n" '\x'
|
||||
|
||||
Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
|
||||
Z2=$'\a\b\e\f\r\v'
|
||||
|
||||
if [ "$Z1" != "$Z2" ]; then
|
||||
echo "whoops: printf %b and $'' differ" >&2
|
||||
fi
|
||||
unset Z1 Z2
|
||||
|
||||
printf -- "--%b--\n" ''
|
||||
printf -- "--%b--\n"
|
||||
|
||||
# the stuff following the \c should be ignored, as well as the rest
|
||||
# of the format string
|
||||
printf -- "--%b--\n" '4.2\c5.4\n'; printf "\n"
|
||||
|
||||
# unrecognized escape sequences should by displayed unchanged
|
||||
printf -- "--%b--\n" '4\.2'
|
||||
|
||||
# a bare \ should not be processed as an escape sequence
|
||||
printf -- "--%b--\n" '\'
|
||||
|
||||
# make sure extra arguments are ignored if the format string doesn't
|
||||
# actually use them
|
||||
printf "\n" 4.4 BSD
|
||||
printf " " 4.4 BSD ; printf "\n"
|
||||
|
||||
# make sure that a fieldwidth and precision of `*' are handled right
|
||||
printf "%10.8s\n" 4.4BSD
|
||||
printf "%*.*s\n" 10 8 4.4BSD
|
||||
|
||||
printf "%10.8q\n" 4.4BSD
|
||||
printf "%*.*q\n" 10 8 4.4BSD
|
||||
|
||||
printf "%6b\n" 4.4BSD
|
||||
printf "%*b\n" 6 4.4BSD
|
||||
|
||||
# we handle this crap with homemade code in printf.def
|
||||
printf "%10b\n" 4.4BSD
|
||||
printf -- "--%-10b--\n" 4.4BSD
|
||||
printf "%4.2b\n" 4.4BSD
|
||||
printf "%.3b\n" 4.4BSD
|
||||
printf -- "--%-8b--\n" 4.4BSD
|
||||
|
||||
# test numeric conversions -- these four lines should echo identically
|
||||
printf "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
|
||||
printf "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
|
||||
printf "%10d\n" 42
|
||||
printf "%10d\n" -42
|
||||
|
||||
printf "%*d\n" 10 42
|
||||
printf "%*d\n" 10 -42
|
||||
|
||||
# test some simple floating point formats
|
||||
printf "%4.2f\n" 4.2
|
||||
printf "%#4.2f\n" 4.2
|
||||
printf "%#4.1f\n" 4.2
|
||||
|
||||
printf "%*.*f\n" 4 2 4.2
|
||||
printf "%#*.*f\n" 4 2 4.2
|
||||
printf "%#*.*f\n" 4 1 4.2
|
||||
|
||||
printf "%E\n" 4.2
|
||||
printf "%e\n" 4.2
|
||||
printf "%6.1E\n" 4.2
|
||||
printf "%6.1e\n" 4.2
|
||||
|
||||
printf "%G\n" 4.2
|
||||
printf "%g\n" 4.2
|
||||
printf "%6.2G\n" 4.2
|
||||
printf "%6.2g\n" 4.2
|
||||
|
||||
# test some of the more esoteric features of POSIX.1 printf
|
||||
printf "%d\n" "'string'"
|
||||
printf "%d\n" '"string"'
|
||||
|
||||
printf "%#o\n" "'string'"
|
||||
printf "%#o\n" '"string"'
|
||||
|
||||
printf "%#x\n" "'string'"
|
||||
printf "%#X\n" '"string"'
|
||||
|
||||
printf "%6.2f\n" "'string'"
|
||||
printf "%6.2f\n" '"string"'
|
||||
|
||||
# output from these two lines had better be the same
|
||||
printf -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
# and these two also
|
||||
printf -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
# tests for translating \' to ' and \\ to \
|
||||
# printf translates \' to ' in the format string...
|
||||
printf "\'abcd\'\n"
|
||||
|
||||
# but not when the %b format specification is used
|
||||
printf "%b\n" \\\'abcd\\\'
|
||||
|
||||
# but both translate \\ to \
|
||||
printf '\\abcd\\\n'
|
||||
printf "%b\n" '\\abcd\\'
|
||||
|
||||
# this was reported as a bug in bash-2.03
|
||||
# these three lines should all echo `26'
|
||||
printf "%d\n" 0x1a
|
||||
printf "%d\n" 032
|
||||
printf "%d\n" 26
|
||||
|
||||
# error messages
|
||||
|
||||
# this should be an overflow, but error messages vary between systems
|
||||
# printf "%lu\n" 4294967296
|
||||
|
||||
# ...but we cannot use this because some systems (SunOS4, for example),
|
||||
# happily ignore overflow conditions in strtol(3)
|
||||
#printf "%ld\n" 4294967296
|
||||
|
||||
printf "%10"
|
||||
printf "ab%Mcd\n"
|
||||
|
||||
# this caused an infinite loop in older versions of printf
|
||||
printf "%y" 0
|
||||
|
||||
# these should print a warning and `0', according to POSIX.2
|
||||
printf "%d\n" GNU
|
||||
printf "%o\n" GNU
|
||||
|
||||
# failures in all bash versions through bash-2.05
|
||||
printf "%.0s" foo
|
||||
printf "%.*s" 0 foo
|
||||
|
||||
printf '%.0b-%.0s\n' foo bar
|
||||
printf '(%*b)(%*s)\n' -4 foo -4 bar
|
||||
|
||||
format='%'`printf '%0100384d' 0`'d\n'
|
||||
printf $format 0
|
||||
|
||||
# failures in all bash versions through bash-3.0 - undercounted characters
|
||||
unset vv
|
||||
printf " %s %s %s \n%n" ab cd ef vv
|
||||
echo "$vv"
|
||||
|
||||
# this doesn't work with printf(3) on all systems
|
||||
#printf "%'s\n" foo
|
||||
|
||||
# test cases from an austin-group list discussion
|
||||
# prints ^G as an extension
|
||||
printf '%b\n' '\7'
|
||||
|
||||
# prints ^G
|
||||
printf '%b\n' '\0007'
|
||||
|
||||
# prints NUL then 7
|
||||
printf '\0007\n'
|
||||
|
||||
# prints no more than two hex digits
|
||||
printf '\x07e\n'
|
||||
|
||||
# additional backslash escapes
|
||||
printf '\"\?\n'
|
||||
|
||||
# failures with decimal precisions until after bash-3.1
|
||||
printf '%0.5d\n' 1
|
||||
|
||||
printf '%05d\n' 1
|
||||
printf '%5d\n' 1
|
||||
printf '%0d\n' 1
|
||||
|
||||
# failures with various floating point formats and 0 after bash-3.2
|
||||
|
||||
printf "%G\n" 0
|
||||
printf "%g\n" 0
|
||||
printf "%4.2G\n" 0
|
||||
printf "%4.2g\n" 0
|
||||
|
||||
printf "%G\n" 4
|
||||
printf "%g\n" 4
|
||||
printf "%4.2G\n" 4
|
||||
printf "%4.2g\n" 4
|
||||
|
||||
printf "%F\n" 0
|
||||
printf "%f\n" 0
|
||||
printf "%4.2F\n" 0
|
||||
printf "%4.2f\n" 0
|
||||
|
||||
printf "%F\n" 4
|
||||
printf "%f\n" 4
|
||||
printf "%4.2F\n" 4
|
||||
printf "%4.2f\n" 4
|
||||
|
||||
printf "%E\n" 0
|
||||
printf "%e\n" 0
|
||||
printf "%4.2E\n" 0
|
||||
printf "%4.2e\n" 0
|
||||
|
||||
printf "%E\n" 4
|
||||
printf "%e\n" 4
|
||||
printf "%4.2E\n" 4
|
||||
printf "%4.2e\n" 4
|
||||
|
||||
printf "%08X\n" 2604292517
|
||||
|
||||
# make sure these format specifiers all output '' for empty string arguments
|
||||
echo q
|
||||
printf "%q\n" ""
|
||||
printf "%q\n"
|
||||
|
||||
echo s
|
||||
printf "%s\n" ''
|
||||
printf "%s\n"
|
||||
|
||||
echo b
|
||||
printf "%b\n" ''
|
||||
printf "%b\n"
|
||||
|
||||
# bug in bash versions up to and including bash-3.2
|
||||
v=yyy
|
||||
printf -v var "%s" '/current/working/directory/*.@(m3|i3|ig|mg)'
|
||||
shopt -s nullglob extglob
|
||||
echo "x$(printf "%b" @(hugo))x"
|
||||
printf -v var "%b" @(hugo); echo "x${var}x"
|
||||
|
||||
${THIS_SH} ./printf2.sub
|
||||
|
||||
${THIS_SH} ./printf3.sub
|
||||
@@ -1,338 +0,0 @@
|
||||
LC_ALL=C
|
||||
LC_NUMERIC=C
|
||||
|
||||
unset vv
|
||||
|
||||
# this should expand escape sequences in the format string, nothing else
|
||||
printf -v vv "\tone\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this should not cut off output after the \c
|
||||
printf -v vv "one\ctwo\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# and unrecognized backslash escapes should have the backslash preserverd
|
||||
printf -v vv "4\.2\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "no newline " ; printf "%s" "$vv" ; printf -v vv "now newline\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# %% -> %
|
||||
printf -v vv "%%\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this was a bug caused by pre-processing the string for backslash escapes
|
||||
# before doing the `%' format processing -- all versions before bash-2.04
|
||||
printf -v vv "\045"
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
printf -v vv "\045d\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# simple character output
|
||||
printf -v vv "%c\n" ABCD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test simple string output
|
||||
printf -v vv "%s\n" unquoted
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test quoted string output
|
||||
printf -v vv "%s %q\n" unquoted quoted
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%s%10q\n" unquoted quoted
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%q\n" 'this&that'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# make sure the format string is reused to use up arguments
|
||||
printf -v vv "%d " 1 2 3 4 5
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# make sure that extra format characters get null arguments
|
||||
printf -v vv "%s %d %d %d\n" onestring
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%s %d %u %4.2f\n" onestring
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%s %s--\n" 4.2 ''
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%s %s--\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test %b escapes
|
||||
|
||||
# 8 is a non-octal digit, so the `81' should be output
|
||||
#printf -v vv -- "--%b--\n" '\n\081'
|
||||
#printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\t\0101'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n" '\t\101'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# these should all display `A7'
|
||||
echo -e "\1017"
|
||||
echo -e "\x417"
|
||||
|
||||
printf -v vv "%b\n" '\01017'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\1017'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\x417'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\"abcd\"'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n" "\'abcd\'"
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" 'a\\x'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv -- "--%b--\n" '\x'
|
||||
printf "%s" "$vv"
|
||||
|
||||
Z1=$(printf -- "%b\n" '\a\b\e\f\r\v')
|
||||
Z2=$'\a\b\e\f\r\v'
|
||||
|
||||
if [ "$Z1" != "$Z2" ]; then
|
||||
printf "%s" "whoops: printf -v vv %b and $'' differ" >&2
|
||||
fi
|
||||
unset Z1 Z2
|
||||
|
||||
printf -v vv -- "--%b--\n" ''
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%b--\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# the stuff following the \c should be ignored, as well as the rest
|
||||
# of the format string
|
||||
printf -v vv -- "--%b--\n" '4.2\c5.4\n'
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# unrecognized escape sequences should by displayed unchanged
|
||||
printf -v vv -- "--%b--\n" '4\.2'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# a bare \ should not be processed as an escape sequence
|
||||
printf -v vv -- "--%b--\n" '\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# make sure extra arguments are ignored if the format string doesn't
|
||||
# actually use them
|
||||
printf -v vv "\n" 4.4 BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv " " 4.4 BSD
|
||||
printf "%s" "$vv"
|
||||
echo
|
||||
|
||||
# make sure that a fieldwidth and precision of `*' are handled right
|
||||
printf -v vv "%10.8s\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*.*s\n" 10 8 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%10.8q\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*.*q\n" 10 8 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%6b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*b\n" 6 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# we handle this crap with homemade code in printf -v vv.def
|
||||
printf -v vv "%10b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%-10b--\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%4.2b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%.3b\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%-8b--\n" 4.4BSD
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test numeric conversions -- these four lines should printf "%s" identically
|
||||
printf -v vv "%d %u %i 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d %u %i %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%ld %lu %li 0%o 0x%x 0x%X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%ld %lu %li %#o %#x %#X\n" 255 255 255 255 255 255
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%10d\n" 42
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%10d\n" -42
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%*d\n" 10 42
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%*d\n" 10 -42
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test some simple floating point formats
|
||||
printf -v vv "%4.2f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#4.2f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#4.1f\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%*.*f\n" 4 2 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#*.*f\n" 4 2 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#*.*f\n" 4 1 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%E\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%e\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.1E\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.1e\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%G\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%g\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2G\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2g\n" 4.2
|
||||
printf "%s" "$vv"
|
||||
|
||||
# test some of the more esoteric features of POSIX.1 printf -v vv
|
||||
printf -v vv "%d\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%#o\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#o\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%#x\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%#X\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv "%6.2f\n" "'string'"
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%6.2f\n" '"string"'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# output from these two lines had better be the same
|
||||
printf -v vv -- "--%6.4s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%6.4b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
|
||||
# and these two also
|
||||
printf -v vv -- "--%12.10s--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
printf -v vv -- "--%12.10b--\n" abcdefghijklmnopqrstuvwxyz
|
||||
printf "%s" "$vv"
|
||||
|
||||
# tests for translating \' to ' and \\ to \
|
||||
# printf -v vv translates \' to ' in the format string...
|
||||
printf -v vv "\'abcd\'\n"
|
||||
printf "%s" "$vv"
|
||||
|
||||
# but not when the %b format specification is used
|
||||
printf -v vv "%b\n" \\\'abcd\\\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# but both translate \\ to \
|
||||
printf -v vv '\\abcd\\\n'
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%b\n" '\\abcd\\'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# this was reported as a bug in bash-2.03
|
||||
# these three lines should all printf "%s" `26'
|
||||
printf -v vv "%d\n" 0x1a
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" 032
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%d\n" 26
|
||||
printf "%s" "$vv"
|
||||
|
||||
# error messages
|
||||
|
||||
# this should be an overflow, but error messages vary between systems
|
||||
# printf -v vv "%lu\n" 4294967296
|
||||
|
||||
# ...but we cannot use this because some systems (SunOS4, for example),
|
||||
# happily ignore overflow conditions in strtol(3)
|
||||
#printf -v vv "%ld\n" 4294967296
|
||||
|
||||
printf -v vv "%10"
|
||||
printf -v vv "ab%Mcd\n"
|
||||
|
||||
# this caused an infinite loop in older versions of printf -v vv
|
||||
printf -v vv "%y" 0
|
||||
|
||||
# these should print a warning and `0', according to POSIX.2
|
||||
printf -v vv "%d\n" GNU
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%o\n" GNU
|
||||
printf "%s" "$vv"
|
||||
|
||||
# failures in all bash versions through bash-2.05
|
||||
printf -v vv "%.0s" foo
|
||||
printf "%s" "$vv"
|
||||
printf -v vv "%.*s" 0 foo
|
||||
printf "%s" "$vv"
|
||||
|
||||
printf -v vv '%.0b-%.0s\n' foo bar
|
||||
printf "%s" "$vv"
|
||||
printf -v vv '(%*b)(%*s)\n' -4 foo -4 bar
|
||||
printf "%s" "$vv"
|
||||
|
||||
format='%'`printf '%0100384d' 0`'d\n'
|
||||
printf -v vv $format 0
|
||||
printf "%s" "$vv"
|
||||
|
||||
# failures in all bash versions through bash-3.0 - undercounted characters
|
||||
unset vv
|
||||
printf -v vv " %s %s %s \n%n" ab cd ef vvv
|
||||
printf "%s" "$vv"
|
||||
echo $vvv
|
||||
|
||||
# this doesn't work with printf -v vv(3) on all systems
|
||||
#printf -v vv "%'s\n" foo
|
||||
|
||||
# test cases from an austin-group list discussion
|
||||
# prints ^G as an extension
|
||||
printf -v vv '%b\n' '\7'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints ^G
|
||||
printf -v vv '%b\n' '\0007'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# prints NUL then 7
|
||||
#printf -v vv '\0007\n'
|
||||
#printf "%s" "$vv"
|
||||
|
||||
# prints no more than two hex digits
|
||||
printf -v vv '\x07e\n'
|
||||
printf "%s" "$vv"
|
||||
|
||||
# additional backslash escapes
|
||||
printf -v vv '\"\?\n'
|
||||
printf "%s" "$vv"
|
||||
@@ -1,6 +0,0 @@
|
||||
echo "warning: UNIX versions number signals and schedule processes differently." >&2
|
||||
echo "warning: If output differing only in line numbers is produced, please" >&2
|
||||
echo "warning: do not consider this a test failure." >&2
|
||||
|
||||
${THIS_SH} ./trap.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx trap.right && rm -f /tmp/xx
|
||||
@@ -1,36 +0,0 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# run-minimal - a version of run-all for shells configured with
|
||||
# --enable-minimal-config
|
||||
#
|
||||
PATH=.:$PATH # just to get the right version of printenv
|
||||
export PATH
|
||||
|
||||
# unset BASH_ENV only if it is set
|
||||
[ "${BASH_ENV+set}" = "set" ] && unset BASH_ENV
|
||||
# ditto for SHELLOPTS
|
||||
#[ "${SHELLOPTS+set}" = "set" ] && unset SHELLOPTS
|
||||
|
||||
: ${THIS_SH:=../bash}
|
||||
export THIS_SH
|
||||
|
||||
${THIS_SH} ./version.mini
|
||||
|
||||
rm -f /tmp/xx
|
||||
|
||||
echo Testing ${THIS_SH}
|
||||
echo Any output from any test, unless otherwise noted, indicates a possible anomaly
|
||||
for x in run-*
|
||||
do
|
||||
case $x in
|
||||
$0) ;;
|
||||
*.orig|*~) ;;
|
||||
run-dollars|run-execscript|run-func|run-getopts|run-heredoc) echo $x ; sh $x ;;
|
||||
run-ifs-tests|run-input-test|run-invert|run-more-exp|run-nquote) echo $x ; sh $x ;;
|
||||
run-ifs-posix|run-posix2|run-posixpat) echo $x ; sh $x ;;
|
||||
run-precedence|run-quote|run-read|run-rhs-exp|run-strip|run-tilde) echo $x ; sh $x ;;
|
||||
*) ;;
|
||||
esac
|
||||
done
|
||||
|
||||
exit 0
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./posixexp.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx posixexp.right && rm -f /tmp/xx
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./posixexp.tests > /tmp/xx
|
||||
diff /tmp/xx posixexp.right && rm -f /tmp/xx
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./posixexp.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx posixexp.right && rm -f /tmp/xx
|
||||
@@ -1,426 +0,0 @@
|
||||
if (( $UID == 0 )); then
|
||||
echo "test-tests: the test suite should not be run as root" >&2
|
||||
fi
|
||||
|
||||
b()
|
||||
{
|
||||
[ "$@" ]
|
||||
echo $?
|
||||
}
|
||||
|
||||
t()
|
||||
{
|
||||
test "$@"
|
||||
echo $?
|
||||
}
|
||||
|
||||
echo 't -a noexist'
|
||||
t -a noexist
|
||||
echo 't -a run-all'
|
||||
t -a run-all
|
||||
|
||||
echo 't -b run-all'
|
||||
t -b run-all
|
||||
echo 't -b /dev/jb1a'
|
||||
t -b /dev/jb1a
|
||||
|
||||
echo 't -c run-all'
|
||||
t -c run-all
|
||||
echo 't -c /dev/tty'
|
||||
t -c /dev/tty
|
||||
|
||||
echo 't -d run-all'
|
||||
t -d run-all
|
||||
echo 't -d /etc'
|
||||
t -d /etc
|
||||
echo 't -d ""'
|
||||
t -d ""
|
||||
echo 'b -d ""'
|
||||
b -d ""
|
||||
|
||||
echo 't -e noexist'
|
||||
t -e noexist
|
||||
echo 't -e run-all'
|
||||
t -e run-all
|
||||
|
||||
echo 't -f noexist'
|
||||
t -f noexist
|
||||
echo 't -f /dev/tty'
|
||||
t -f /dev/tty
|
||||
echo 't -f run-all'
|
||||
t -f run-all
|
||||
|
||||
echo 't -g run-all'
|
||||
t -g run-all
|
||||
|
||||
touch /tmp/test.setgid
|
||||
chgrp ${GROUPS[0]} /tmp/test.setgid
|
||||
chmod ug+x /tmp/test.setgid
|
||||
chmod g+s /tmp/test.setgid
|
||||
echo 't -g /tmp/test.setgid'
|
||||
t -g /tmp/test.setgid
|
||||
rm -f /tmp/test.setgid
|
||||
|
||||
echo 't -k run-all'
|
||||
t -k run-all
|
||||
|
||||
echo 't -n ""'
|
||||
t -n ""
|
||||
echo 't -n "hello"'
|
||||
t -n "hello"
|
||||
|
||||
echo 't -p run-all'
|
||||
t -p run-all
|
||||
|
||||
echo 't -r noexist'
|
||||
t -r noexist
|
||||
|
||||
if (( $UID != 0 )); then
|
||||
touch /tmp/test.noread
|
||||
chmod a-r /tmp/test.noread
|
||||
echo 't -r /tmp/test.noread'
|
||||
t -r /tmp/test.noread
|
||||
rm -f /tmp/test.noread
|
||||
else
|
||||
echo 't -r /tmp/test.noread'
|
||||
echo 1
|
||||
fi
|
||||
|
||||
echo 't -r run-all'
|
||||
t -r run-all
|
||||
|
||||
echo 't -s noexist'
|
||||
t -s noexist
|
||||
echo 't -s /dev/null'
|
||||
t -s /dev/null
|
||||
echo 't -s run-all'
|
||||
t -s run-all
|
||||
|
||||
echo 't -t 20'
|
||||
t -t 20
|
||||
echo 't -t 0'
|
||||
t -t 0 < /dev/tty
|
||||
|
||||
echo 't -u noexist'
|
||||
t -u noexist
|
||||
|
||||
echo 't -u run-all'
|
||||
t -u run-all
|
||||
|
||||
touch /tmp/test.setuid
|
||||
chmod u+x /tmp/test.setuid # some systems require this to turn on setuid bit
|
||||
chmod u+s /tmp/test.setuid
|
||||
echo 't -u /tmp/test.setuid'
|
||||
t -u /tmp/test.setuid
|
||||
rm -f /tmp/test.setuid
|
||||
|
||||
echo 't -w noexist'
|
||||
t -w noexist
|
||||
|
||||
if (( $UID != 0 )); then
|
||||
touch /tmp/test.nowrite
|
||||
chmod a-w /tmp/test.nowrite
|
||||
echo 't -w /tmp/test.nowrite'
|
||||
t -w /tmp/test.nowrite
|
||||
rm -f /tmp/test.nowrite
|
||||
else
|
||||
echo 't -w /tmp/test.nowrite'
|
||||
echo 1
|
||||
fi
|
||||
|
||||
echo 't -w /dev/null'
|
||||
t -w /dev/null
|
||||
|
||||
echo 't -x noexist'
|
||||
t -x noexist
|
||||
|
||||
touch /tmp/test.exec
|
||||
chmod u+x /tmp/test.exec
|
||||
echo 't -x /tmp/test.exec'
|
||||
t -x /tmp/test.exec
|
||||
rm -f /tmp/test.exec
|
||||
|
||||
touch /tmp/test.noexec
|
||||
chmod u-x /tmp/test.noexec
|
||||
echo 't -x /tmp/test.noexec'
|
||||
t -x /tmp/test.noexec
|
||||
rm -f /tmp/test.noexec
|
||||
|
||||
echo 't -z ""'
|
||||
t -z ""
|
||||
echo 't -z "foo"'
|
||||
t -z "foo"
|
||||
|
||||
echo 't "foo"'
|
||||
t "foo"
|
||||
echo 't ""'
|
||||
t ""
|
||||
|
||||
touch /tmp/test.owner
|
||||
echo 't -O /tmp/test.owner'
|
||||
t -O /tmp/test.owner
|
||||
rm -f /tmp/test.owner
|
||||
|
||||
touch /tmp/test.socket
|
||||
echo 't -S /tmp/test.socket'
|
||||
t -S /tmp/test.socket # false
|
||||
rm -f /tmp/test.socket
|
||||
|
||||
touch /tmp/test.newer
|
||||
echo 't -N /tmp/test.newer'
|
||||
t -N /tmp/test.newer
|
||||
rm -f /tmp/test.newer
|
||||
|
||||
echo 't "hello" = "hello"'
|
||||
t "hello" = "hello"
|
||||
echo 't "hello" = "goodbye"'
|
||||
t "hello" = "goodbye"
|
||||
|
||||
echo 't "hello" == "hello"'
|
||||
t "hello" == "hello"
|
||||
echo 't "hello" == "goodbye"'
|
||||
t "hello" == "goodbye"
|
||||
|
||||
echo 't "hello" != "hello"'
|
||||
t "hello" != "hello"
|
||||
echo 't "hello" != "goodbye"'
|
||||
t "hello" != "goodbye"
|
||||
|
||||
echo 't "hello" < "goodbye"'
|
||||
t "hello" \< "goodbye"
|
||||
echo 't "hello" > "goodbye"'
|
||||
t "hello" \> "goodbye"
|
||||
|
||||
echo 't ! "hello" > "goodbye"'
|
||||
t "! hello" \> "goodbye"
|
||||
|
||||
echo 't 200 -eq 200'
|
||||
t 200 -eq 200
|
||||
echo 't 34 -eq 222'
|
||||
t 34 -eq 222
|
||||
echo 't -32 -eq 32'
|
||||
t -32 -eq 32
|
||||
|
||||
echo 't 200 -ne 200'
|
||||
t 200 -ne 200
|
||||
echo 't 34 -ne 222'
|
||||
t 34 -ne 222
|
||||
|
||||
echo 't 200 -gt 200'
|
||||
t 200 -gt 200
|
||||
echo 't 340 -gt 222'
|
||||
t 340 -gt 222
|
||||
|
||||
echo 't 200 -ge 200'
|
||||
t 200 -ge 200
|
||||
echo 't 34 -ge 222'
|
||||
t 34 -ge 222
|
||||
|
||||
echo 't 200 -lt 200'
|
||||
t 200 -lt 200
|
||||
echo 't 34 -lt 222'
|
||||
t 34 -lt 222
|
||||
|
||||
echo 't 200 -le 200'
|
||||
t 200 -le 200
|
||||
echo 't 340 -le 222'
|
||||
t 340 -le 222
|
||||
|
||||
echo 't 700 -le 1000 -a -n "1" -a "20" = "20"'
|
||||
t 700 -le 1000 -a -n "1" -a "20" = "20"
|
||||
echo 't ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
|
||||
t ! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)
|
||||
|
||||
touch /tmp/abc
|
||||
sleep 2
|
||||
touch /tmp/def
|
||||
|
||||
echo 't /tmp/abc -nt /tmp/def'
|
||||
t /tmp/abc -nt /tmp/def
|
||||
echo 't /tmp/abc -ot /tmp/def'
|
||||
t /tmp/abc -ot /tmp/def
|
||||
echo 't /tmp/def -nt /tmp/abc'
|
||||
t /tmp/def -nt /tmp/abc
|
||||
echo 't /tmp/def -ot /tmp/abc'
|
||||
t /tmp/def -ot /tmp/abc
|
||||
|
||||
echo 't /tmp/abc -ef /tmp/def'
|
||||
t /tmp/abc -ef /tmp/def
|
||||
ln /tmp/abc /tmp/ghi
|
||||
echo 't /tmp/abc -ef /tmp/ghi'
|
||||
t /tmp/abc -ef /tmp/ghi
|
||||
|
||||
rm /tmp/abc /tmp/def /tmp/ghi
|
||||
|
||||
echo 't -r /dev/fd/0'
|
||||
t -r /dev/fd/0
|
||||
echo 't -w /dev/fd/1'
|
||||
t -w /dev/fd/1
|
||||
echo 't -w /dev/fd/2'
|
||||
t -w /dev/fd/2
|
||||
|
||||
echo 't -r /dev/stdin'
|
||||
t -r /dev/stdin
|
||||
echo 't -w /dev/stdout'
|
||||
t -w /dev/stdout
|
||||
echo 't -w /dev/stderr'
|
||||
t -w /dev/stderr
|
||||
|
||||
echo 't'
|
||||
t
|
||||
echo 'b'
|
||||
b
|
||||
|
||||
echo 't 12 -eq 34'
|
||||
t 12 -eq 34
|
||||
echo 't ! 12 -eq 34'
|
||||
t ! 12 -eq 34
|
||||
|
||||
echo 't -n abcd -o aaa'
|
||||
t -n abcd -o aaa
|
||||
echo 't -n abcd -o -z aaa'
|
||||
t -n abcd -o -z aaa
|
||||
|
||||
echo 't -n abcd -a aaa'
|
||||
t -n abcd -a aaa
|
||||
echo 't -n abcd -a -z aaa'
|
||||
t -n abcd -a -z aaa
|
||||
|
||||
set +o allexport
|
||||
echo 't -o allexport'
|
||||
t -o allexport
|
||||
echo 't ! -o allexport'
|
||||
t ! -o allexport
|
||||
|
||||
echo 't xx -a yy'
|
||||
t xx -a yy
|
||||
echo 't xx -o ""'
|
||||
t xx -o ""
|
||||
echo 't xx -a ""'
|
||||
t xx -a ""
|
||||
|
||||
echo 't -X -a -X'
|
||||
t -X -a -X
|
||||
echo 't -X -o -X'
|
||||
t -X -o -X
|
||||
echo 't -X -o ""'
|
||||
t -X -o ""
|
||||
echo 't -X -a ""'
|
||||
t -X -a ""
|
||||
echo 't "" -a -X'
|
||||
t "" -a -X
|
||||
echo 't "" -o -X'
|
||||
t "" -o -X
|
||||
echo 't "" -a ""'
|
||||
t "" -a ""
|
||||
echo 't "" -o ""'
|
||||
t "" -o ""
|
||||
echo 't true -o -X'
|
||||
t true -o -X
|
||||
echo 't true -a -X'
|
||||
t true -a -X
|
||||
|
||||
echo 't ( -E )'
|
||||
t \( -E \)
|
||||
echo 't ( "" )'
|
||||
t \( "" \)
|
||||
|
||||
z=42
|
||||
|
||||
echo 't ! -z "$z"'
|
||||
t ! -z "$z"
|
||||
|
||||
echo 't ! -n "$z"'
|
||||
t ! -n "$z"
|
||||
|
||||
zero=
|
||||
echo 't "$zero"'
|
||||
t "$zero"
|
||||
echo 't ! "$zero"'
|
||||
t ! "$zero"
|
||||
echo 'b "$zero"'
|
||||
b "$zero"
|
||||
echo 'b ! "$zero"'
|
||||
b ! "$zero"
|
||||
|
||||
touch /tmp/test.group
|
||||
chgrp ${GROUPS[0]} /tmp/test.group
|
||||
echo 't -G /tmp/test.group'
|
||||
t -G /tmp/test.group
|
||||
rm /tmp/test.group
|
||||
|
||||
case "${THIS_SH}" in
|
||||
/*) SHNAME=${THIS_SH} ;;
|
||||
*) SHNAME=${PWD}/${THIS_SH} ;;
|
||||
esac
|
||||
|
||||
if ln -s ${SHNAME} /tmp/test.symlink 2>/dev/null; then
|
||||
chgrp ${GROUPS[0]} /tmp/test.symlink 2>/dev/null
|
||||
echo 't -h /tmp/test.symlink'
|
||||
t -h /tmp/test.symlink
|
||||
# some systems don't let you remove this
|
||||
rm -f /tmp/test.symlink 2>/dev/null
|
||||
else
|
||||
echo 't -h /tmp/test.symlink'
|
||||
echo 0
|
||||
fi
|
||||
|
||||
# arithmetic constant errors
|
||||
echo "t 4+3 -eq 7"
|
||||
t 4+3 -eq 7
|
||||
echo "b 4-5 -eq 7"
|
||||
b 4+3 -eq 7
|
||||
|
||||
echo "t 9 -eq 4+5"
|
||||
t 9 -eq 4+5
|
||||
echo "b 9 -eq 4+5"
|
||||
b 9 -eq 4+5
|
||||
|
||||
A=7
|
||||
echo "t A -eq 7"
|
||||
t A -eq 7
|
||||
echo "b A -eq 7"
|
||||
b A -eq 7
|
||||
|
||||
B=9
|
||||
echo "t 9 -eq B"
|
||||
t 9 -eq B
|
||||
echo "b 9 -eq B"
|
||||
b 9 -eq B
|
||||
|
||||
# badly formed expressions
|
||||
echo 't ( 1 = 2'
|
||||
t \( 1 = 2
|
||||
echo 'b ( 1 = 2'
|
||||
b \( 1 = 2
|
||||
|
||||
# more errors
|
||||
t a b
|
||||
t a b c
|
||||
t -A v
|
||||
# too many arguments -- argument expected is also reasonable
|
||||
t 4 -eq 4 -a 2 -ne 5 -a 4 -ne
|
||||
# too many arguments
|
||||
t 4 -eq 4 -a 3 4
|
||||
|
||||
[
|
||||
echo $?
|
||||
|
||||
t \( \)
|
||||
|
||||
# non-numeric arguments to `test -t' should return failure -- fix in 2.05
|
||||
echo 't -t a'
|
||||
t -t a
|
||||
echo 't -t addsds'
|
||||
t -t addsds
|
||||
echo 't -t 42'
|
||||
t -t 42
|
||||
echo 't -t /dev/tty'
|
||||
t -t /dev/tty
|
||||
echo 't -t /dev/tty4'
|
||||
t -t /dev/tty4
|
||||
echo 't -t /dev/tty4444444...'
|
||||
t -t /dev/tty4444444...
|
||||
|
||||
# fixed in bash-4.0-beta
|
||||
t -t ' '
|
||||
@@ -1,93 +0,0 @@
|
||||
set +o posix
|
||||
|
||||
hash -r
|
||||
unalias -a
|
||||
|
||||
# this should echo nothing
|
||||
type
|
||||
# this should be a usage error
|
||||
type -r ${THIS_SH}
|
||||
|
||||
# these should behave identically
|
||||
type notthere
|
||||
command -v notthere
|
||||
|
||||
alias m=more
|
||||
|
||||
unset -f func 2>/dev/null
|
||||
func() { echo this is func; }
|
||||
|
||||
type -t func
|
||||
type -t while
|
||||
type -t builtin
|
||||
type -t /bin/sh
|
||||
type -t ${THIS_SH}
|
||||
type -t mv
|
||||
|
||||
type func
|
||||
# the following two should produce identical output
|
||||
type while
|
||||
type -a while
|
||||
type builtin
|
||||
type /bin/sh
|
||||
|
||||
command -v func
|
||||
command -V func
|
||||
command -v while
|
||||
command -V while
|
||||
|
||||
# the following two lines should produce the same output
|
||||
# post-3.0 patch makes command -v silent, as posix specifies
|
||||
# first test with alias expansion off (should all fail or produce no output)
|
||||
type -t m
|
||||
type m
|
||||
command -v m
|
||||
alias -p
|
||||
alias m
|
||||
|
||||
# then test with alias expansion on
|
||||
shopt -s expand_aliases
|
||||
type m
|
||||
type -t m
|
||||
command -v m
|
||||
alias -p
|
||||
alias m
|
||||
|
||||
command -V m
|
||||
shopt -u expand_aliases
|
||||
|
||||
command -v builtin
|
||||
command -V builtin
|
||||
command -v /bin/sh
|
||||
command -V /bin/sh
|
||||
|
||||
unset -f func
|
||||
type func
|
||||
unalias m
|
||||
type m
|
||||
|
||||
hash -r
|
||||
|
||||
hash -p /bin/sh sh
|
||||
type -p sh
|
||||
|
||||
SHBASE=${THIS_SH##*/}
|
||||
hash -p /tmp/$SHBASE $SHBASE
|
||||
type -p $SHBASE
|
||||
type $SHBASE
|
||||
|
||||
type -t $SHBASE
|
||||
|
||||
# make sure the hash table looks right
|
||||
hash
|
||||
|
||||
# bug in versions of bash up to and including bash-3.2
|
||||
f() {
|
||||
v=$'\001'
|
||||
}
|
||||
|
||||
type f | cat -v
|
||||
|
||||
${THIS_SH} type1.sub
|
||||
|
||||
${THIS_SH} type2.sub
|
||||
Reference in New Issue
Block a user