mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-02 01:40:49 +02:00
bash-4.0 remove leftover and stray files
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
Unless otherwise stated, all files in this directory are Copyright (C)
|
||||
1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,
|
||||
2004,2005,2006,2007,2008
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
The file ifs-posix.tests is Copyright (C) 2005 Glen Fowler.
|
||||
@@ -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,284 +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))
|
||||
|
||||
# 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
|
||||
|
||||
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,384 +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"
|
||||
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
|
||||
@@ -1,123 +0,0 @@
|
||||
# test cases for array quoting and escaping fixed post bash-3.2-release
|
||||
|
||||
oIFS="$IFS"
|
||||
|
||||
a=(a b c)
|
||||
echo ${a[@]}
|
||||
|
||||
a2=("${a[@]/#/"-iname '"}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
echo "${dbg-"'hey'"}"
|
||||
echo "${dbg-"hey"}"
|
||||
echo "${dbg-'"'hey}"
|
||||
echo "${dbg-'"hey'}"
|
||||
|
||||
unset a a2
|
||||
|
||||
IFS=
|
||||
a2=(${a[@]/#/"-iname '"})
|
||||
recho "${a2[@]}"
|
||||
|
||||
IFS="$oIFS"
|
||||
unset a a2
|
||||
|
||||
a=('a b' 'c d' 'e f')
|
||||
|
||||
recho ${a[@]:1:2}
|
||||
recho "${a[@]:1:2}"
|
||||
|
||||
IFS=
|
||||
recho ${a[@]:1:2}
|
||||
recho "${a[@]:1:2}"
|
||||
|
||||
IFS="$oIFS"
|
||||
unset a a2
|
||||
|
||||
a=(abc def)
|
||||
|
||||
# Prevent word splitting
|
||||
#IFS=
|
||||
|
||||
a2=("${a[@]/#/"-iname '"}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
eval a2=("${a[@]/#/"-iname '"}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
a2=("${a[@]/#/-iname \'}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
eval a2=("${a[@]/#/-iname \'}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
set -- abc def
|
||||
|
||||
a2=("${@/#/"-iname '"}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
eval a2=("${@/#/"-iname '"}")
|
||||
recho "${a2[@]}"
|
||||
|
||||
unset a a2
|
||||
|
||||
IFS=
|
||||
pat=('*.*')
|
||||
case $(ls ${pat[@]} 2>/dev/null) in
|
||||
'') echo '*.* BAD' ;;
|
||||
*) echo '*.* OK' ;;
|
||||
esac
|
||||
|
||||
IFS="$oIFS"
|
||||
unset a a2 pat
|
||||
|
||||
IFS=
|
||||
|
||||
s='abc'
|
||||
|
||||
set - ${s/b/1 2 3}
|
||||
echo $#
|
||||
echo "$1"
|
||||
|
||||
IFS="$oIFS"
|
||||
unset s
|
||||
|
||||
set -- ab cd ef
|
||||
foo="var with spaces"
|
||||
|
||||
IFS=
|
||||
recho $foo
|
||||
recho "$foo"
|
||||
|
||||
recho ${foo}"$@"
|
||||
recho ${foo}$@
|
||||
|
||||
array=(ab cd ef)
|
||||
recho ${foo}"${array[@]}"
|
||||
recho ${foo}${array[@]}
|
||||
|
||||
recho $(echo $foo)"$@"
|
||||
recho $(echo $foo)$@
|
||||
|
||||
a=('word1 with spaces' 'word2 with spaces')
|
||||
set - ${a[@]/word/element}
|
||||
echo $#
|
||||
recho "$@"
|
||||
recho $@
|
||||
|
||||
IFS="$oIFS"
|
||||
unset a a2 array foo
|
||||
|
||||
a=$'ab\001cd\001ef'
|
||||
|
||||
recho $a
|
||||
recho "$a"
|
||||
|
||||
recho $(echo $a)
|
||||
recho $(echo "$a")
|
||||
|
||||
# XXX - this doesn't work right until post-bash-3.2
|
||||
IFS=$'\001'
|
||||
recho $a
|
||||
|
||||
IFS=$'\001' recho "$a"
|
||||
@@ -1,78 +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"}
|
||||
@@ -1,14 +0,0 @@
|
||||
unset CDPATH
|
||||
|
||||
MYDIR=$(pwd -P)
|
||||
FULLDIR=/tmp/bash-dir-a
|
||||
DIR=${FULLDIR##*/}
|
||||
|
||||
mkdir $FULLDIR
|
||||
CDPATH=.:/tmp
|
||||
cd $DIR
|
||||
pwd
|
||||
echo $PWD
|
||||
|
||||
cd $MYDIR
|
||||
rmdir $FULLDIR
|
||||
@@ -1,96 +0,0 @@
|
||||
S1=acknowledgement
|
||||
S2=oenophile
|
||||
|
||||
echo ${S1^}
|
||||
echo ${S1^^}
|
||||
|
||||
echo ${S2^[aeiou]}
|
||||
echo ${S2^^[aeiou]}
|
||||
|
||||
U1=${S1^^}
|
||||
U2=${S2^^}
|
||||
|
||||
echo ${U1,}
|
||||
echo ${U1,,}
|
||||
|
||||
echo ${U2,}
|
||||
echo ${U2,[AEIOU]}
|
||||
echo ${U2,,[AEIOU]}
|
||||
|
||||
A1=( $S1 $S2 )
|
||||
|
||||
echo ${A1[@]^[aeiou]}
|
||||
echo ${A1[@]^^[aeiou]}
|
||||
|
||||
A2=( $U1 $U2 )
|
||||
|
||||
echo ${A2[@],[AEIOU]}
|
||||
echo ${A2[@],,[AEIOU]}
|
||||
|
||||
echo ${A2[@],?}
|
||||
echo ${A2[@],,?}
|
||||
|
||||
declare -A AA1 AA2
|
||||
|
||||
AA1[ack]=$S1
|
||||
AA1[oen]=$S2
|
||||
|
||||
echo ${AA1[@]^}
|
||||
echo ${AA1[@]^^}
|
||||
|
||||
echo ${AA1[@]^[aeiou]}
|
||||
echo ${AA1[@]^^[aeiou]}
|
||||
|
||||
AA2[ACK]=$U1
|
||||
AA2[OEN]=$U2
|
||||
|
||||
echo ${AA2[@],}
|
||||
echo ${AA2[@],,}
|
||||
|
||||
echo ${AA2[@],[AEIOU]}
|
||||
echo ${AA2[@],,[AEIOU]}
|
||||
|
||||
set -- $S1 $S2
|
||||
|
||||
echo ${@^}
|
||||
echo ${@^^}
|
||||
|
||||
|
||||
echo ${S1^[rstlne]} ${S2^[rstlne]}
|
||||
echo ${S1^^[rstlne]} ${S2^^[rstlne]}
|
||||
|
||||
echo ${@^[rstlne]}
|
||||
echo ${@^^[rstlne]}
|
||||
|
||||
echo ${S1,[rstlne]} ${S2,[rstlne]}
|
||||
echo ${S1,,[rstlne]} ${S2,,[rstlne]}
|
||||
|
||||
echo ${@,[rstlne]}
|
||||
echo ${@,,[rstlne]}
|
||||
|
||||
echo ${@^?}
|
||||
echo ${@^^?}
|
||||
|
||||
# make sure that multiple words in the string are handled as other expansions
|
||||
TEXT="Be Conservative in what you send and Liberal in what you accept"
|
||||
TEXT2="be conservative in what you send and liberal in what you accept"
|
||||
|
||||
declare -u foo
|
||||
foo=$TEXT
|
||||
echo $foo
|
||||
|
||||
declare -l bar
|
||||
bar=$TEXT
|
||||
echo $bar
|
||||
|
||||
declare -c qux
|
||||
qux=$TEXT
|
||||
echo $qux
|
||||
qux=$TEXT2
|
||||
echo $qux
|
||||
|
||||
echo ${TEXT,}
|
||||
echo ${TEXT,,}
|
||||
|
||||
echo ${TEXT^}
|
||||
echo ${TEXT^^}
|
||||
@@ -1,10 +0,0 @@
|
||||
foo=$(cat <<EOF
|
||||
hi
|
||||
EOF )
|
||||
echo $foo
|
||||
|
||||
foo=`cat <<EOF
|
||||
hi
|
||||
EOF`
|
||||
echo $foo
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
foo=$(cat <<EOF
|
||||
hi
|
||||
EOF )
|
||||
echo $foo
|
||||
|
||||
foo=`cat <<EOF
|
||||
hi
|
||||
EOF`
|
||||
echo $foo
|
||||
|
||||
@@ -1,197 +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
|
||||
)
|
||||
@@ -1,179 +0,0 @@
|
||||
#
|
||||
# the test/[ code is tested elsewhere, and the [[...]] just uses the same
|
||||
# code. this tests the special features of [[...]]
|
||||
#
|
||||
TDIR=/usr/homes/chet
|
||||
|
||||
# this one is straight out of the ksh88 book
|
||||
[[ foo > bar && $PWD -ef . ]]
|
||||
echo returns: $?
|
||||
|
||||
# [[ x ]] is equivalent to [[ -n x ]]
|
||||
[[ x ]]
|
||||
echo returns: $?
|
||||
|
||||
# [[ ! x ]] is equivalent to [[ ! -n x ]]
|
||||
[[ ! x ]]
|
||||
echo returns: $?
|
||||
|
||||
# ! binds tighter than test/[ -- it binds to a term, not an expression
|
||||
[[ ! x || x ]]
|
||||
echo returns: $?
|
||||
|
||||
# parenthesized terms didn't work right until post-2.04
|
||||
[[ a ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ (a) ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ -n a ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ (-n a) ]]
|
||||
echo returns: $?
|
||||
|
||||
# unset variables don't need to be quoted
|
||||
[[ -n $UNSET ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ -z $UNSET ]]
|
||||
echo returns: $?
|
||||
|
||||
# the ==/= and != operators do pattern matching
|
||||
[[ $TDIR == /usr/homes/* ]]
|
||||
echo returns: $?
|
||||
|
||||
# ...but you can quote any part of the pattern to have it matched as a string
|
||||
[[ $TDIR == /usr/homes/\* ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ $TDIR == '/usr/homes/*' ]]
|
||||
echo returns: $?
|
||||
|
||||
# if the first part of && fails, the second is not executed
|
||||
[[ -n $UNSET && $UNSET == foo ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ -z $UNSET && $UNSET == foo ]]
|
||||
echo returns: $?
|
||||
|
||||
# if the first part of || succeeds, the second is not executed
|
||||
[[ -z $UNSET || -d $PWD ]]
|
||||
echo returns: $?
|
||||
|
||||
# if the rhs were executed, it would be an error
|
||||
[[ -n $TDIR || $HOME -ef ${H*} ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ -n $TDIR && -z $UNSET || $HOME -ef ${H*} ]]
|
||||
echo returns: $?
|
||||
|
||||
# && has a higher parsing precedence than ||
|
||||
[[ -n $TDIR && -n $UNSET || $TDIR -ef . ]]
|
||||
echo returns: $?
|
||||
|
||||
# ...but expressions in parentheses may be used to override precedence rules
|
||||
[[ -n $TDIR || -n $UNSET && $PWD -ef xyz ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ ( -n $TDIR || -n $UNSET ) && $PWD -ef xyz ]]
|
||||
echo returns: $?
|
||||
|
||||
# some arithmetic tests for completeness -- see what happens with missing
|
||||
# operands, bad expressions, makes sure arguments are evaluated as
|
||||
# arithmetic expressions, etc.
|
||||
|
||||
unset IVAR A
|
||||
[[ 7 -gt $IVAR ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ $IVAR -gt 7 ]]
|
||||
echo returns: $?
|
||||
|
||||
IVAR=4
|
||||
[[ $IVAR -gt 7 ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ 7 -eq 4+3 ]]
|
||||
echo returns: $?
|
||||
|
||||
[[ 7 -eq 4+ ]]
|
||||
echo returns: $?
|
||||
|
||||
IVAR=4+3
|
||||
[[ $IVAR -eq 7 ]]
|
||||
echo returns: $?
|
||||
|
||||
A=7
|
||||
[[ $IVAR -eq A ]]
|
||||
echo returns: $?
|
||||
|
||||
unset IVAR A
|
||||
|
||||
# more pattern matching tests
|
||||
|
||||
[[ $filename == *.c ]]
|
||||
echo returns: $?
|
||||
|
||||
filename=patmatch.c
|
||||
|
||||
[[ $filename == *.c ]]
|
||||
echo returns: $?
|
||||
|
||||
# the extended globbing features may be used when matching patterns
|
||||
shopt -s extglob
|
||||
|
||||
arg=-7
|
||||
|
||||
[[ $arg == -+([0-9]) ]]
|
||||
echo returns: $?
|
||||
|
||||
arg=-H
|
||||
|
||||
[[ $arg == -+([0-9]) ]]
|
||||
echo returns: $?
|
||||
|
||||
arg=+4
|
||||
[[ $arg == ++([0-9]) ]]
|
||||
echo returns: $?
|
||||
|
||||
# make sure the null string is never matched if the string is not null
|
||||
STR=file.c
|
||||
PAT=
|
||||
|
||||
if [[ $STR = $PAT ]]; then
|
||||
echo oops
|
||||
fi
|
||||
|
||||
# but that if the string is null, a null pattern is matched correctly
|
||||
STR=
|
||||
PAT=
|
||||
|
||||
if [[ $STR = $PAT ]]; then
|
||||
echo ok
|
||||
fi
|
||||
|
||||
# test the regular expression conditional operator
|
||||
[[ jbig2dec-0.9-i586-001.tgz =~ ([^-]+)-([^-]+)-([^-]+)-0*([1-9][0-9]*)\.tgz ]]
|
||||
echo ${BASH_REMATCH[1]}
|
||||
|
||||
LDD_BASH=" linux-gate.so.1 => (0xffffe000)
|
||||
libreadline.so.5 => /lib/libreadline.so.5 (0xb7f91000)
|
||||
libhistory.so.5 => /lib/libhistory.so.5 (0xb7f8a000)
|
||||
libncurses.so.5 => /lib/libncurses.so.5 (0xb7f55000)
|
||||
libdl.so.2 => /lib/libdl.so.2 (0xb7f51000)
|
||||
libc.so.6 => /lib/libc.so.6 (0xb7e34000)
|
||||
/lib/ld-linux.so.2 (0xb7fd0000)"
|
||||
|
||||
[[ "$LDD_BASH" =~ "libc" ]] && echo "found 1"
|
||||
echo ${BASH_REMATCH[@]}
|
||||
|
||||
[[ "$LDD_BASH" =~ libc ]] && echo "found 2"
|
||||
echo ${BASH_REMATCH[@]}
|
||||
|
||||
# bug in all versions up to and including bash-2.05b
|
||||
if [[ "123abc" == *?(a)bc ]]; then echo ok 42; else echo bad 42; fi
|
||||
if [[ "123abc" == *?(a)bc ]]; then echo ok 43; else echo bad 43; fi
|
||||
|
||||
${THIS_SH} ./cond-regexp.sub
|
||||
@@ -1,45 +0,0 @@
|
||||
coproc { echo a b c; sleep 2; }
|
||||
|
||||
echo $COPROC_PID
|
||||
echo ${COPROC[@]}
|
||||
|
||||
read LINE <&${COPROC[0]}
|
||||
echo $LINE
|
||||
|
||||
wait $COPROC_PID
|
||||
|
||||
coproc REFLECT { cat - ; }
|
||||
|
||||
echo $REFLECT_PID
|
||||
echo ${REFLECT[@]}
|
||||
|
||||
echo flop >&${REFLECT[1]}
|
||||
read LINE <&${REFLECT[0]}
|
||||
|
||||
echo $LINE
|
||||
|
||||
kill $REFLECT_PID
|
||||
wait $REFLECT_PID
|
||||
|
||||
coproc tr -u 'a-z' 'A-Z'
|
||||
|
||||
echo $COPROC_PID
|
||||
echo ${COPROC[@]}
|
||||
|
||||
echo foo >&${COPROC[1]}
|
||||
read <&${COPROC[0]}
|
||||
|
||||
echo $REPLY
|
||||
echo ${COPROC[@]}
|
||||
|
||||
cat /etc/passwd | grep root | awk -F: '{print $1;}'
|
||||
|
||||
exec 4<&${COPROC[0]}-
|
||||
exec >&${COPROC[1]}-
|
||||
|
||||
echo ${COPROC[@]}
|
||||
|
||||
read foo <&4
|
||||
echo $foo >&2
|
||||
|
||||
exit 0
|
||||
@@ -1,72 +0,0 @@
|
||||
tf is a function
|
||||
tf ()
|
||||
{
|
||||
echo this is ${0##*/} >/dev/null;
|
||||
echo a | cat - >/dev/null;
|
||||
test -f ${0##*/} && echo ${0##*/} is a regular file;
|
||||
test -d ${0##*/} || echo ${0##*/} is not a directory;
|
||||
echo a;
|
||||
echo b;
|
||||
echo c;
|
||||
echo background >/dev/null & ( exit 1 );
|
||||
echo $?;
|
||||
{
|
||||
echo a
|
||||
};
|
||||
i=0;
|
||||
while (( " i < 3 " )); do
|
||||
test -r /dev/fd/$i;
|
||||
i=$(( i + 1 ));
|
||||
done;
|
||||
[[ -r /dev/fd/0 && -w /dev/fd/1 ]] || echo oops >/dev/null;
|
||||
for name in $( echo 1 2 3 );
|
||||
do
|
||||
test -r /dev/fd/$name;
|
||||
done;
|
||||
if [[ -r /dev/fd/0 && -w /dev/fd/1 ]]; then
|
||||
echo ok >/dev/null;
|
||||
else
|
||||
if (( " 7 > 40 " )); then
|
||||
echo oops;
|
||||
else
|
||||
echo done;
|
||||
fi;
|
||||
fi >/dev/null;
|
||||
case $PATH in
|
||||
*$PWD*)
|
||||
echo \$PWD in \$PATH
|
||||
;;
|
||||
*)
|
||||
echo \$PWD not in \$PATH
|
||||
;;
|
||||
esac >/dev/null;
|
||||
while false; do
|
||||
echo z;
|
||||
done >/dev/null;
|
||||
until true; do
|
||||
echo z;
|
||||
done >/dev/null;
|
||||
echo \&\|'()' \{ echo abcde \; \};
|
||||
eval fu\%nc'()' \{ echo abcde \; \};
|
||||
type fu\%nc
|
||||
}
|
||||
tf2 is a function
|
||||
tf2 ()
|
||||
{
|
||||
( {
|
||||
time -p echo a | cat - >/dev/null
|
||||
} ) 2>&1
|
||||
}
|
||||
cprint.tests is a regular file
|
||||
cprint.tests is not a directory
|
||||
a
|
||||
b
|
||||
c
|
||||
1
|
||||
a
|
||||
&|() { echo abcde ; }
|
||||
fu%nc is a function
|
||||
fu%nc ()
|
||||
{
|
||||
echo abcde
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
#
|
||||
# a nonsense script and shell function to test out the command printing code
|
||||
#
|
||||
tf()
|
||||
{
|
||||
# simple command with redir
|
||||
echo this is ${0##*/} > /dev/null
|
||||
|
||||
# pipeline
|
||||
echo a | cat - > /dev/null
|
||||
|
||||
test -f ${0##*/} && echo ${0##*/} is a regular file
|
||||
test -d ${0##*/} || echo ${0##*/} is not a directory
|
||||
|
||||
echo a ; echo b ; echo c
|
||||
|
||||
echo background >/dev/null &
|
||||
|
||||
( exit 1 )
|
||||
echo $?
|
||||
|
||||
{ echo a ; }
|
||||
|
||||
i=0
|
||||
while (( i < 3 )); do
|
||||
test -r /dev/fd/$i
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
|
||||
[[ -r /dev/fd/0 && -w /dev/fd/1 ]] || echo oops > /dev/null
|
||||
|
||||
for name in $( echo 1 2 3 ); do
|
||||
test -r /dev/fd/$name
|
||||
done
|
||||
|
||||
if [[ -r /dev/fd/0 && -w /dev/fd/1 ]] ; then
|
||||
echo ok > /dev/null
|
||||
elif (( 7 > 40 )) ; then
|
||||
echo oops
|
||||
else
|
||||
echo done
|
||||
fi > /dev/null
|
||||
|
||||
case $PATH in
|
||||
*$PWD*) echo \$PWD in \$PATH ;;
|
||||
*) echo \$PWD not in \$PATH ;;
|
||||
esac > /dev/null
|
||||
|
||||
while false; do echo z; done > /dev/null
|
||||
|
||||
until true; do echo z ; done > /dev/null
|
||||
|
||||
echo \&\|'()' \{ echo abcde \; \}
|
||||
# when not in POSIX mode, we can have weirdly-named functions
|
||||
eval fu\%nc'()' \{ echo abcde \; \}
|
||||
type fu\%nc
|
||||
}
|
||||
|
||||
tf2()
|
||||
{
|
||||
( { time -p echo a | cat - > /dev/null ; } ) 2>&1
|
||||
}
|
||||
|
||||
type tf
|
||||
type tf2
|
||||
|
||||
tf
|
||||
@@ -1,87 +0,0 @@
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
dirs -c
|
||||
# error -- nonexistant directory
|
||||
pushd /tmp/xxx-notthere
|
||||
|
||||
# errors -- empty stack
|
||||
pushd
|
||||
popd
|
||||
|
||||
# errors -- bad numeric arguments -- should not cause the script to exit
|
||||
pushd -m
|
||||
popd -m
|
||||
dirs -m
|
||||
dirs 7
|
||||
|
||||
MYDIR=$PWD
|
||||
unalias cd 2>/dev/null
|
||||
|
||||
unalias -a
|
||||
|
||||
command cd -P /
|
||||
command pwd -P # better be `/'
|
||||
|
||||
case "$OLDPWD" in
|
||||
$MYDIR) echo ok ;;
|
||||
*) echo oops -- bad \$OLDPWD ;;
|
||||
esac
|
||||
|
||||
pushd /usr
|
||||
echo $PWD $OLDPWD
|
||||
dirs
|
||||
echo ${DIRSTACK[@]}
|
||||
|
||||
# this should not change the directory stack at all
|
||||
pushd -n +0
|
||||
dirs
|
||||
|
||||
popd
|
||||
pushd /usr
|
||||
|
||||
pushd /etc
|
||||
dirs
|
||||
dirs -l
|
||||
dirs -v
|
||||
|
||||
# two consecutive `pushd's should swap the top two stack elements, then
|
||||
# swap them back, leaving the stack intact
|
||||
pushd
|
||||
pushd
|
||||
|
||||
pushd /tmp
|
||||
echo ${DIRSTACK[0]} ; dirs +0
|
||||
echo ${DIRSTACK[2]} ; dirs +2
|
||||
|
||||
# these should be errors, but not affect the directory stack
|
||||
dirs +9; dirs -9
|
||||
pushd +9 ; pushd -9
|
||||
popd +9 ; popd -9
|
||||
|
||||
popd -n +2
|
||||
dirs
|
||||
echo ${DIRSTACK[@]}
|
||||
|
||||
pushd -n /usr
|
||||
echo $PWD
|
||||
dirs
|
||||
echo ${DIRSTACK[@]}
|
||||
|
||||
builtin pwd
|
||||
|
||||
DIRSTACK[1]=/bin
|
||||
dirs
|
||||
|
||||
builtin pwd
|
||||
popd +2
|
||||
builtin pwd -L
|
||||
pushd -1
|
||||
dirs
|
||||
echo ${DIRSTACK[0]}
|
||||
|
||||
dirs -c
|
||||
dirs
|
||||
|
||||
# this is for the benefit of pure coverage
|
||||
cd $MYDIR
|
||||
@@ -1,56 +0,0 @@
|
||||
before exec1.sub: one two three
|
||||
calling exec1.sub
|
||||
aa bb cc dd ee
|
||||
after exec1.sub with args: 0
|
||||
|
||||
after exec1.sub without args: 0
|
||||
./execscript: line 20: notthere: command not found
|
||||
127
|
||||
/tmp/bash: notthere: No such file or directory
|
||||
127
|
||||
/bin/sh: /bin/sh: cannot execute binary file
|
||||
126
|
||||
./execscript: line 39: /: is a directory
|
||||
126
|
||||
/: /: is a directory
|
||||
126
|
||||
./execscript: line 46: .: /: is a directory
|
||||
1
|
||||
127
|
||||
0
|
||||
this is bashenv
|
||||
./exec3.sub: line 3: /tmp/bash-notthere: No such file or directory
|
||||
./exec3.sub: line 3: exec: /tmp/bash-notthere: cannot execute: No such file or directory
|
||||
126
|
||||
./execscript: line 68: notthere: No such file or directory
|
||||
127
|
||||
./execscript: line 71: notthere: No such file or directory
|
||||
127
|
||||
./execscript: line 74: notthere: No such file or directory
|
||||
127
|
||||
this is sh
|
||||
this is sh
|
||||
unset
|
||||
ok
|
||||
5
|
||||
./exec5.sub: line 4: exec: bash-notthere: not found
|
||||
127
|
||||
this is ohio-state
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
42
|
||||
42
|
||||
0
|
||||
1
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
||||
testb
|
||||
bash: no job control in this shell
|
||||
expand_aliases on
|
||||
after
|
||||
@@ -1,382 +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
|
||||
@@ -1,365 +0,0 @@
|
||||
# test the ksh-like extended globbing features: [!@*?+](patlist)
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
expect()
|
||||
{
|
||||
echo expect "$@"
|
||||
}
|
||||
|
||||
case "/dev/udp/129.22.8.102/45" in
|
||||
/dev/@(tcp|udp)/*/*) echo ok 1;;
|
||||
*) echo bad 1;;
|
||||
esac
|
||||
|
||||
# valid numbers
|
||||
case 12 in
|
||||
0|[1-9]*([0-9])) echo ok 2;;
|
||||
*) echo bad 2;;
|
||||
esac
|
||||
|
||||
case 12abc in
|
||||
0|[1-9]*([0-9])) echo bad 3;;
|
||||
*) echo ok 3;;
|
||||
esac
|
||||
|
||||
case 1 in
|
||||
0|[1-9]*([0-9])) echo ok 4;;
|
||||
*) echo bad 4;;
|
||||
esac
|
||||
|
||||
# octal numbers
|
||||
case 07 in
|
||||
+([0-7])) echo ok 5;;
|
||||
*) echo bad 5;;
|
||||
esac
|
||||
|
||||
case 0377 in
|
||||
+([0-7])) echo ok 6;;
|
||||
*) echo bad 6;;
|
||||
esac
|
||||
|
||||
case 09 in
|
||||
+([0-7])) echo bad 7;;
|
||||
*) echo ok 7;;
|
||||
esac
|
||||
|
||||
# stuff from korn's book
|
||||
case paragraph in
|
||||
para@(chute|graph)) echo ok 8;;
|
||||
*) echo bad 8;;
|
||||
esac
|
||||
|
||||
case paramour in
|
||||
para@(chute|graph)) echo bad 9;;
|
||||
*) echo ok 9;;
|
||||
esac
|
||||
|
||||
case para991 in
|
||||
para?([345]|99)1) echo ok 10;;
|
||||
*) echo bad 10;;
|
||||
esac
|
||||
|
||||
case para381 in
|
||||
para?([345]|99)1) echo bad 11;;
|
||||
*) echo ok 11;;
|
||||
esac
|
||||
|
||||
case paragraph in
|
||||
para*([0-9])) echo bad 12;;
|
||||
*) echo ok 12;;
|
||||
esac
|
||||
|
||||
case para in
|
||||
para*([0-9])) echo ok 13;;
|
||||
*) echo bad 13;;
|
||||
esac
|
||||
|
||||
case para13829383746592 in
|
||||
para*([0-9])) echo ok 14;;
|
||||
*) echo bad 14;;
|
||||
esac
|
||||
|
||||
case paragraph in
|
||||
para*([0-9])) echo bad 15;;
|
||||
*) echo ok 15;;
|
||||
esac
|
||||
|
||||
case para in
|
||||
para+([0-9])) echo bad 16;;
|
||||
*) echo ok 16;;
|
||||
esac
|
||||
|
||||
case para987346523 in
|
||||
para+([0-9])) echo ok 17;;
|
||||
*) echo bad 17;;
|
||||
esac
|
||||
|
||||
case paragraph in
|
||||
para!(*.[0-9])) echo ok 18;;
|
||||
*) echo bad 18;;
|
||||
esac
|
||||
|
||||
case para.38 in
|
||||
para!(*.[0-9])) echo ok 19;;
|
||||
*) echo bad 19;;
|
||||
esac
|
||||
|
||||
case para.graph in
|
||||
para!(*.[0-9])) echo ok 20;;
|
||||
*) echo bad 20;;
|
||||
esac
|
||||
|
||||
case para39 in
|
||||
para!(*.[0-9])) echo ok 21;;
|
||||
*) echo bad 21;;
|
||||
esac
|
||||
|
||||
# tests derived from those in rosenblatt's korn shell book
|
||||
|
||||
case "" in
|
||||
*(0|1|3|5|7|9)) echo ok 22;;
|
||||
*) echo bad 22;
|
||||
esac
|
||||
|
||||
case 137577991 in
|
||||
*(0|1|3|5|7|9)) echo ok 23;;
|
||||
*) echo bad 23;
|
||||
esac
|
||||
|
||||
case 2468 in
|
||||
*(0|1|3|5|7|9)) echo bad 24;;
|
||||
*) echo ok 24;
|
||||
esac
|
||||
|
||||
case file.c in
|
||||
*.c?(c)) echo ok 25;;
|
||||
*) echo bad 25;;
|
||||
esac
|
||||
|
||||
case file.C in
|
||||
*.c?(c)) echo bad 26;;
|
||||
*) echo ok 26;;
|
||||
esac
|
||||
|
||||
case file.cc in
|
||||
*.c?(c)) echo ok 27;;
|
||||
*) echo bad 27;;
|
||||
esac
|
||||
|
||||
case file.ccc in
|
||||
*.c?(c)) echo bad 28;;
|
||||
*) echo ok 28;;
|
||||
esac
|
||||
|
||||
case parse.y in
|
||||
!(*.c|*.h|Makefile.in|config*|README)) echo ok 29;;
|
||||
*) echo bad 29;;
|
||||
esac
|
||||
|
||||
case shell.c in
|
||||
!(*.c|*.h|Makefile.in|config*|README)) echo bad 30;;
|
||||
*) echo ok 30;;
|
||||
esac
|
||||
|
||||
case Makefile in
|
||||
!(*.c|*.h|Makefile.in|config*|README)) echo ok 31;;
|
||||
*) echo bad 31;;
|
||||
esac
|
||||
|
||||
case "VMS.FILE;1" in
|
||||
*\;[1-9]*([0-9])) echo ok 32;;
|
||||
*) echo bad 32;;
|
||||
esac
|
||||
|
||||
case "VMS.FILE;0" in
|
||||
*\;[1-9]*([0-9])) echo bad 33;;
|
||||
*) echo ok 33;;
|
||||
esac
|
||||
case "VMS.FILE;" in
|
||||
*\;[1-9]*([0-9])) echo bad 34;;
|
||||
*) echo ok 34;;
|
||||
esac
|
||||
case "VMS.FILE;139" in
|
||||
*\;[1-9]*([0-9])) echo ok 35;;
|
||||
*) echo bad 35;;
|
||||
esac
|
||||
case "VMS.FILE;1N" in
|
||||
*\;[1-9]*([0-9])) echo bad 36;;
|
||||
*) echo ok 36;;
|
||||
esac
|
||||
|
||||
# tests derived from the pd-ksh test suite
|
||||
|
||||
MYDIR=$PWD # save where we are
|
||||
|
||||
TESTDIR=/tmp/eglob-test-$$
|
||||
mkdir $TESTDIR
|
||||
builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
|
||||
rm -rf *
|
||||
|
||||
touch abcx abcz bbc
|
||||
expect '!([*)*'
|
||||
echo !([*)*
|
||||
|
||||
expect '+(a|b[)*'
|
||||
echo +(a|b[)*
|
||||
|
||||
expect '[a*(]*z'
|
||||
echo [a*(]*)z
|
||||
|
||||
rm -f abcx abcz bbc
|
||||
|
||||
touch abc
|
||||
|
||||
expect '+()c'
|
||||
echo +()c
|
||||
expect '+()x'
|
||||
echo +()x
|
||||
expect abc
|
||||
echo +(*)c
|
||||
expect '+(*)x'
|
||||
echo +(*)x
|
||||
|
||||
# extended globbing should not be performed on the output of substitutions
|
||||
x='@(*)'
|
||||
expect '@(*)'
|
||||
echo $x
|
||||
|
||||
expect 'no-file+(a|b)stuff'
|
||||
echo no-file+(a|b)stuff
|
||||
expect 'no-file+(a*(c)|b)stuff'
|
||||
echo no-file+(a*(c)|b)stuff
|
||||
|
||||
touch abd acd
|
||||
|
||||
expect 'abd acd'
|
||||
echo a+(b|c)d
|
||||
|
||||
expect 'acd'
|
||||
echo a!(@(b|B))d
|
||||
|
||||
expect 'abd'
|
||||
echo a[b*(foo|bar)]d
|
||||
|
||||
# simple kleene star tests
|
||||
expect no
|
||||
case foo in *(a|b[)) echo yes;; *) echo no;; esac
|
||||
|
||||
expect yes
|
||||
case foo in *(a|b[)|f*) echo yes;; *) echo no;; esac
|
||||
|
||||
# this doesn't work right yet; it is an incorrectly formed pattern
|
||||
expect yes
|
||||
case '*(a|b[)' in *(a|b[)) echo yes;; *) echo no;; esac
|
||||
|
||||
# check extended globbing in pattern removal -- these don't work right yet
|
||||
x=abcdef
|
||||
|
||||
expect '1: bcdef'
|
||||
echo 1: ${x#+(a|abc)}
|
||||
expect '2: def'
|
||||
echo 2: ${x##+(a|abc)}
|
||||
expect '3: abcde'
|
||||
echo 3: ${x%+(def|f)}
|
||||
expect '4: abc'
|
||||
echo 4: ${x%%+(f|def)}
|
||||
|
||||
# these work ok
|
||||
|
||||
expect '5: ef'
|
||||
echo 5: ${x#*(a|b)cd}
|
||||
expect '6: ef'
|
||||
echo 6: "${x#*(a|b)cd}"
|
||||
expect '7: abcdef'
|
||||
echo 7: ${x#"*(a|b)cd"}
|
||||
|
||||
# More tests derived from a bug report concerning extended glob patterns
|
||||
# following a *
|
||||
builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; }
|
||||
rm -rf *
|
||||
|
||||
touch ab abcdef abef abcfef
|
||||
|
||||
expect 'ab abef'
|
||||
echo ab*(e|f)
|
||||
|
||||
expect 'abcfef abef'
|
||||
echo ab?*(e|f)
|
||||
|
||||
expect abcdef
|
||||
echo ab*d+(e|f)
|
||||
|
||||
expect 'ab abcdef abcfef abef'
|
||||
echo ab**(e|f)
|
||||
|
||||
expect 'abcdef abcfef abef'
|
||||
echo ab*+(e|f)
|
||||
|
||||
case 'abcfefg' in
|
||||
ab**(e|f)) echo ok 37;;
|
||||
*) echo bad 37;;
|
||||
esac
|
||||
|
||||
case 'abcfefg' in
|
||||
ab**(e|f)g) echo ok 38;;
|
||||
*a) echo bad 38;;
|
||||
esac
|
||||
|
||||
case ab in
|
||||
ab*+(e|f)) echo bad 39;;
|
||||
*) echo ok 39;;
|
||||
esac
|
||||
|
||||
case abef in
|
||||
ab***ef) echo ok 40;;
|
||||
*) echo bad 40;;
|
||||
esac
|
||||
|
||||
case abef in
|
||||
ab**) echo ok 41;;
|
||||
*) echo bad 41;;
|
||||
esac
|
||||
|
||||
# bug in all versions up to and including bash-2.05b
|
||||
case "123abc" in
|
||||
*?(a)bc) echo ok 42;;
|
||||
*) echo bad 42;;
|
||||
esac
|
||||
|
||||
# clean up and do the next one
|
||||
|
||||
builtin cd /
|
||||
rm -rf $TESTDIR
|
||||
|
||||
mkdir $TESTDIR
|
||||
builtin cd $TESTDIR
|
||||
|
||||
LC_COLLATE=C # have to set this; it affects the sorting
|
||||
touch a.b a,b a:b a-b a\;b a\ b a_b
|
||||
|
||||
echo a[^[:alnum:]]b
|
||||
echo a[-.,:\;\ _]b
|
||||
|
||||
echo a@([^[:alnum:]])b
|
||||
echo a@([-.,:; _])b
|
||||
echo a@([.])b
|
||||
echo a@([^.])b
|
||||
echo a@([^x])b
|
||||
echo a+([^[:alnum:]])b
|
||||
|
||||
echo a@(.|[^[:alnum:]])b
|
||||
|
||||
builtin cd /
|
||||
rm -rf $TESTDIR
|
||||
|
||||
x=abcdef
|
||||
recho "${x#*(a|b)cd}"
|
||||
|
||||
# this is for the benefit of pure coverage, so it writes the pcv file
|
||||
# in the right place
|
||||
builtin cd $MYDIR
|
||||
|
||||
${THIS_SH} ./extglob1.sub
|
||||
|
||||
exit 0
|
||||
@@ -1,37 +0,0 @@
|
||||
MYDIR=$PWD
|
||||
|
||||
: ${TMPDIR:=/tmp}
|
||||
GDIR=$TMPDIR/gtest-$$
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
mkdir $GDIR || exit 1
|
||||
cd $GDIR || exit 1
|
||||
|
||||
touch a.c
|
||||
|
||||
echo +([[:alpha:].])
|
||||
echo +([[:alpha:].])+([[:alpha:].])
|
||||
echo *([[:alpha:].])
|
||||
echo *([[:alpha:].])*([[:alpha:].])
|
||||
|
||||
echo ?([[:alpha:].])?([[:alpha:].])?([[:alpha:].])
|
||||
echo @([[:alpha:].])@([[:alpha:].])@([[:alpha:].])
|
||||
|
||||
case . in
|
||||
!([[:alpha:].]) ) echo bad 1;;
|
||||
*) echo ok 1;;
|
||||
esac
|
||||
|
||||
case . in
|
||||
?([[:alpha:].]) ) echo ok 2;;
|
||||
*) echo bad 2;;
|
||||
esac
|
||||
|
||||
case . in
|
||||
@([[:alpha:].]) ) echo ok 3;;
|
||||
*) echo bad 3;;
|
||||
esac
|
||||
|
||||
cd $MYDIR
|
||||
rm -rf $GDIR
|
||||
@@ -1,97 +0,0 @@
|
||||
trap 'rm /tmp/newhistory' 0
|
||||
|
||||
# bad options
|
||||
history -x
|
||||
# cannot use -r and -w at the same time
|
||||
history -r -w /dev/null
|
||||
|
||||
# bad option
|
||||
fc -v
|
||||
|
||||
# all of these should result in an empty history list
|
||||
history -c
|
||||
history -r /dev/null
|
||||
history -n /dev/null
|
||||
history -c
|
||||
|
||||
HISTFILE=history.list
|
||||
HISTCONTROL=ignoreboth
|
||||
HISTIGNORE='&:history*:fc*'
|
||||
HISTSIZE=32
|
||||
|
||||
shopt -s cmdhist
|
||||
set -o history
|
||||
|
||||
history
|
||||
|
||||
fc -l
|
||||
fc -nl
|
||||
|
||||
fc -lr
|
||||
fc -nlr
|
||||
|
||||
history -s "echo line for history"
|
||||
history
|
||||
|
||||
history -p '!!'
|
||||
|
||||
fc -nl
|
||||
|
||||
HISTFILE=/tmp/newhistory
|
||||
history -a
|
||||
echo displaying \$HISTFILE after history -a
|
||||
cat $HISTFILE
|
||||
|
||||
history
|
||||
history -w
|
||||
cat $HISTFILE
|
||||
|
||||
history -s "echo line 2 for history"
|
||||
history
|
||||
history -p '!e'
|
||||
history -p '!!'
|
||||
|
||||
# this should show up as one history entry
|
||||
for x in one two three
|
||||
do
|
||||
:
|
||||
done
|
||||
history
|
||||
|
||||
# just a basic test. a full test suite for history expansion should be
|
||||
# created
|
||||
set -H
|
||||
!!
|
||||
!e
|
||||
|
||||
unset HISTSIZE
|
||||
unset HISTFILE
|
||||
|
||||
fc -l 4
|
||||
fc -l 4 8
|
||||
|
||||
fc -l 502
|
||||
fc -l one=two three=four 502
|
||||
|
||||
history 4
|
||||
|
||||
shopt -so history
|
||||
shopt -s expand_aliases
|
||||
|
||||
alias r="fc -s"
|
||||
|
||||
echo aa ab ac
|
||||
|
||||
r a=x
|
||||
r x=4 b=8
|
||||
|
||||
# this had better fail with `no command found'
|
||||
r cc
|
||||
|
||||
unalias -a
|
||||
alias
|
||||
|
||||
set +o history
|
||||
|
||||
shopt -q -o history
|
||||
echo $?
|
||||
@@ -1,109 +0,0 @@
|
||||
trap 'rm /tmp/newhistory' 0
|
||||
|
||||
# bad options
|
||||
history -x
|
||||
# cannot use -r and -w at the same time
|
||||
history -r -w /dev/null
|
||||
|
||||
# bad option
|
||||
fc -v
|
||||
|
||||
unset HISTFILESIZE
|
||||
|
||||
# all of these should result in an empty history list
|
||||
history -c
|
||||
history -r /dev/null
|
||||
history -n /dev/null
|
||||
history -c
|
||||
|
||||
HISTFILE=history.list
|
||||
HISTCONTROL=ignoreboth
|
||||
HISTIGNORE='&:history*:fc*'
|
||||
HISTSIZE=32
|
||||
|
||||
shopt -s cmdhist
|
||||
set -o history
|
||||
|
||||
history
|
||||
|
||||
fc -l
|
||||
fc -nl
|
||||
|
||||
fc -lr
|
||||
fc -nlr
|
||||
|
||||
history -s "echo line for history"
|
||||
history
|
||||
|
||||
history -p '!!'
|
||||
|
||||
fc -nl
|
||||
|
||||
HISTFILE=/tmp/newhistory
|
||||
history -a
|
||||
echo displaying \$HISTFILE after history -a
|
||||
cat $HISTFILE
|
||||
|
||||
history
|
||||
history -w
|
||||
cat $HISTFILE
|
||||
|
||||
history -s "echo line 2 for history"
|
||||
history
|
||||
history -p '!e'
|
||||
history -p '!!'
|
||||
|
||||
# this should show up as one history entry
|
||||
for x in one two three
|
||||
do
|
||||
:
|
||||
done
|
||||
history
|
||||
|
||||
# just a basic test. a full test suite for history expansion should be
|
||||
# created
|
||||
set -H
|
||||
!!
|
||||
!e
|
||||
|
||||
unset HISTSIZE
|
||||
unset HISTFILE
|
||||
|
||||
fc -l 4
|
||||
fc -l 4 8
|
||||
|
||||
fc -l one=two three=four 502
|
||||
|
||||
history 4
|
||||
|
||||
shopt -so history
|
||||
shopt -s expand_aliases
|
||||
|
||||
alias r="fc -s"
|
||||
|
||||
echo aa ab ac
|
||||
|
||||
r a=x
|
||||
r x=4 b=8
|
||||
|
||||
# this had better fail with `no command found'
|
||||
r cc
|
||||
|
||||
unalias -a
|
||||
alias
|
||||
|
||||
# these two blocks had better both result in the same output
|
||||
echo aa
|
||||
echo bb
|
||||
echo cc
|
||||
fc -e cat
|
||||
|
||||
echo aa
|
||||
echo bb
|
||||
echo cc
|
||||
fc -e cat -1
|
||||
|
||||
set +o history
|
||||
|
||||
shopt -q -o history
|
||||
echo $?
|
||||
@@ -1,11 +0,0 @@
|
||||
set -o history
|
||||
|
||||
history -c
|
||||
cat <<!
|
||||
one
|
||||
two
|
||||
three
|
||||
!
|
||||
|
||||
history
|
||||
fc -s 2
|
||||
@@ -1,40 +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
|
||||
|
||||
${THIS_SH} ./intl1.sub
|
||||
@@ -1,42 +0,0 @@
|
||||
declare -a A
|
||||
mapfile A < mapfile.data
|
||||
for (( i = 0 ; i < ${#A[@]} ; i++ )); do
|
||||
echo -n "${A[${i}]}"
|
||||
done
|
||||
|
||||
declare -a B
|
||||
mapfile -t B < mapfile.data
|
||||
for (( i = 0 ; i < ${#B[@]} ; i++ )); do
|
||||
echo "${B[${i}]}"
|
||||
done
|
||||
|
||||
mapfile -C "echo" -c 1 A < mapfile.data
|
||||
mapfile -C "echo" -c 3 A < mapfile.data
|
||||
mapfile -C "echo" -c 19 A < mapfile.data
|
||||
|
||||
declare -a C
|
||||
mapfile -t -u 3 C 3< mapfile.data < mapfile.tests
|
||||
for (( i = 0 ; i < ${#C[@]} ; i++ )); do
|
||||
echo "${C[${i}]}"
|
||||
done
|
||||
|
||||
|
||||
declare -a D
|
||||
for (( i = 0 ; i < 30; i++ )); do
|
||||
D[${i}]="[$i] aaa"
|
||||
done
|
||||
mapfile -O 10 -t D < mapfile.data
|
||||
for (( i = 0 ; i < ${#D[@]} ; i++ )); do
|
||||
echo "${D[${i}]}"
|
||||
done
|
||||
|
||||
declare -a E
|
||||
for (( i = 0 ; i < 30; i++ )); do
|
||||
E[${i}]="[$i] aaa"
|
||||
done
|
||||
mapfile -O 10 -n 5 -t E < mapfile.data
|
||||
for (( i = 0 ; i < ${#E[@]} ; i++ )); do
|
||||
echo "${E[${i}]}"
|
||||
done
|
||||
|
||||
# ${THIS_SH} ./mapfile1.sub
|
||||
@@ -1,11 +0,0 @@
|
||||
: ${TMPDIR:=/tmp}
|
||||
FILE=$TMPDIR/file
|
||||
|
||||
trap 'rm -f $FILE' 0 1 2 3 6 15
|
||||
echo {1..20} > $FILE
|
||||
|
||||
mapfile -n 5 array < $FILE
|
||||
echo ${array[@]}
|
||||
|
||||
mapfile -n 5 -c 1 -C "echo foo" array < $FILE
|
||||
mapfile -n 5 -c 1 -C "echo foo" array < /dev/null
|
||||
@@ -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,562 +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
|
||||
expect '<./new-exp.tests: -2: substring expression < 0>'
|
||||
c=${var:0:-2}
|
||||
|
||||
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##?}
|
||||
|
||||
${THIS_SH} ./new-exp6.sub
|
||||
|
||||
${THIS_SH} ./new-exp7.sub
|
||||
|
||||
# this must be last!
|
||||
expect $0: 'ABXD: parameter unset'
|
||||
recho ${ABXD:?"parameter unset"}
|
||||
@@ -1,94 +0,0 @@
|
||||
a=$'a\001b'
|
||||
|
||||
set $a
|
||||
|
||||
b=$a
|
||||
c=$1
|
||||
d="$1"
|
||||
|
||||
e=$'uv\001\001wx'
|
||||
f=$'uv\001w\001xy'
|
||||
|
||||
set $e $e
|
||||
|
||||
recho ${e%%??}
|
||||
recho "${e%%??}"
|
||||
|
||||
recho ${e%%???}
|
||||
recho "${e%%???}"
|
||||
|
||||
recho ${a#?}
|
||||
recho "${a#?}"
|
||||
|
||||
# simple variables
|
||||
|
||||
recho ${f##*$'\001'}
|
||||
recho "${f##*$'\001'}"
|
||||
recho ${f##*''} # literal ^A
|
||||
recho "${f##*'^A'}" # two characters, `^' and `A'
|
||||
|
||||
recho ${e%$'\001'*}
|
||||
recho "${e%$'\001'*}"
|
||||
recho ${e#*$'\001'}
|
||||
recho "${e#*$'\001'}"
|
||||
|
||||
# array members
|
||||
|
||||
arr[0]=$e
|
||||
arr[1]=$f
|
||||
|
||||
recho ${arr[1]##*$'\001'}
|
||||
recho "${arr[1]##*$'\001'}"
|
||||
recho ${arr[1]##*''} # literal ^A
|
||||
recho "${arr[1]##*'^A'}" # two characters, `^' and `A'
|
||||
|
||||
recho ${arr[0]%$'\001'*}
|
||||
recho "${arr[0]%$'\001'*}"
|
||||
recho ${arr[0]#*$'\001'}
|
||||
recho "${arr[0]#*$'\001'}"
|
||||
|
||||
recho ${arr%$'\001'*}
|
||||
recho "${arr%$'\001'*}"
|
||||
recho ${arr#*$'\001'}
|
||||
recho "${arr#*$'\001'}"
|
||||
|
||||
# positional parameters
|
||||
|
||||
set $e $f
|
||||
|
||||
recho ${2##*$'\001'}
|
||||
recho "${2##*$'\001'}"
|
||||
recho ${2##*''} # literal ^A
|
||||
recho "${2##*''}" # literal ^A
|
||||
recho ${2##*'^A'} # two characters, `^' and `A'
|
||||
recho "${2##*'^A'}" # two characters, `^' and `A'
|
||||
|
||||
recho ${1%$'\001'*}
|
||||
recho "${1%$'\001'*}"
|
||||
recho ${1#*$'\001'}
|
||||
recho "${1#*$'\001'}"
|
||||
|
||||
recho ${@%$'\001'*}
|
||||
recho "${@%$'\001'*}"
|
||||
recho ${@#*$'\001'}
|
||||
recho "${@#*$'\001'}"
|
||||
recho ${@##*''} # literal ^A
|
||||
recho "${@##*'^A'}" # two characters, `^' and `A'
|
||||
|
||||
# arrays treated as a whole
|
||||
|
||||
recho ${arr[@]%$'\001'*}
|
||||
recho "${arr[@]%$'\001'*}"
|
||||
recho ${arr[@]#*$'\001'}
|
||||
recho "${arr[@]#*$'\001'}"
|
||||
recho ${arr[@]##*''} # literal ^A
|
||||
recho "${arr[@]##*'^A'}" # two characters, `^' and `A'
|
||||
|
||||
# make sure command substitution works with CTLESC as well
|
||||
a=$'ab\001cd\001ef'
|
||||
|
||||
recho $a
|
||||
recho "$a"
|
||||
|
||||
recho $(echo $a)
|
||||
recho $(echo "$a")
|
||||
@@ -1,43 +0,0 @@
|
||||
a=$'ab\001cd\001ef'
|
||||
IFS=$'\001'
|
||||
|
||||
recho $a
|
||||
recho ${a}
|
||||
recho xx${a}yy
|
||||
recho "$a"
|
||||
|
||||
recho $(echo $a)
|
||||
recho $(echo "$a")
|
||||
|
||||
recho ${a%%??}
|
||||
recho "${a%%??}"
|
||||
|
||||
recho ${a/f/}
|
||||
recho "${a/f/}"
|
||||
|
||||
a1=("$a")
|
||||
recho ${a1[0]}
|
||||
recho ${a1}
|
||||
|
||||
recho ${a:2:2}
|
||||
|
||||
set -- $a
|
||||
recho $1 -- $2 -- $3
|
||||
|
||||
set -- "$a"
|
||||
recho $1
|
||||
recho ${1}
|
||||
|
||||
echo "$a" | { IFS=$'\001' read x y z; recho $x -- $y -- $z ; }
|
||||
unset x y z
|
||||
b=$'uv\177wx\177yz'
|
||||
|
||||
recho $b
|
||||
|
||||
recho "ab${x}y${a}z"
|
||||
recho ab${x}y${a}z
|
||||
|
||||
recho "ab${b}y${a}z"
|
||||
recho ab${b}y${a}z
|
||||
|
||||
echo "ab${b}y${a}z" | { IFS=$'\001' read l m n o ; recho $l -- $m -- $n -- $o; }
|
||||
@@ -1,309 +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"
|
||||
@@ -1,95 +0,0 @@
|
||||
echo " a " | (read x; echo "$x.")
|
||||
|
||||
echo " a b " | ( read x y ; echo -"$x"-"$y"- )
|
||||
echo " a b\ " | ( read x y ; echo -"$x"-"$y"- )
|
||||
echo " a b " | ( read x ; echo -"$x"- )
|
||||
echo " a b\ " | ( read x ; echo -"$x"- )
|
||||
|
||||
echo " a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
|
||||
echo " a b\ " | ( read -r x ; echo -"$x"- )
|
||||
|
||||
echo "\ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
|
||||
echo "\ a b\ " | ( read -r x ; echo -"$x"- )
|
||||
echo " \ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
|
||||
echo " \ a b\ " | ( read -r x ; echo -"$x"- )
|
||||
|
||||
# make sure that CTLESC and CTLNUL are passed through correctly
|
||||
echo $'\001' | ( read var ; recho "$var" )
|
||||
echo $'\001' | ( read ; recho "$REPLY" )
|
||||
|
||||
echo $'\177' | ( read var ; recho "$var" )
|
||||
echo $'\177' | ( read ; recho "$REPLY" )
|
||||
|
||||
# make sure a backslash-quoted \\n still disappears from the input when
|
||||
# we're not reading in `raw' mode, and no stray CTLESC chars are left in
|
||||
# the input stream
|
||||
echo $'ab\\\ncd' | ( read ; recho "$REPLY" )
|
||||
|
||||
echo "A B " > /tmp/IN
|
||||
unset x y z
|
||||
read x y z < /tmp/IN
|
||||
echo 1: "x[$x] y[$y] z[$z]"
|
||||
echo 1a: ${z-z not set}
|
||||
read x < /tmp/IN
|
||||
echo 2: "x[$x]"
|
||||
rm /tmp/IN
|
||||
|
||||
# this is where the bash `read' behavior with respect to $REPLY differs
|
||||
# from ksh93
|
||||
echo "A B " > /tmp/IN
|
||||
|
||||
read < /tmp/IN
|
||||
echo "[$REPLY]"
|
||||
|
||||
rm /tmp/IN
|
||||
|
||||
echo " A B " > /tmp/IN
|
||||
|
||||
read < /tmp/IN
|
||||
echo "[$REPLY]"
|
||||
|
||||
rm /tmp/IN
|
||||
|
||||
# make sure that read with more variables than words sets the extra
|
||||
# variables to the empty string
|
||||
|
||||
bvar=bvar
|
||||
cvar=cvar
|
||||
echo aa > /tmp/IN
|
||||
read avar bvar cvar < /tmp/IN
|
||||
echo =="$avar"==
|
||||
echo =="$bvar"==
|
||||
echo =="$cvar"==
|
||||
|
||||
rm /tmp/IN
|
||||
|
||||
# test behavior of read with various settings of IFS
|
||||
|
||||
echo " foo" | { IFS= read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS= ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { unset IFS ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS=$'\n' ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS=$' \n' ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
|
||||
|
||||
echo " foo" | { IFS=$':' ; read line; recho "$line"; }
|
||||
|
||||
# test read -d delim behavior
|
||||
${THIS_SH} ./read1.sub
|
||||
|
||||
# test read -t timeout behavior
|
||||
${THIS_SH} ./read2.sub
|
||||
|
||||
# test read -n nchars behavior
|
||||
${THIS_SH} ./read3.sub
|
||||
|
||||
# test read -u fd behavior
|
||||
${THIS_SH} ./read4.sub
|
||||
|
||||
# test behavior when IFS is not the default -- bug through bash-2.05b
|
||||
${THIS_SH} ./read5.sub
|
||||
@@ -1,12 +0,0 @@
|
||||
# test read with a timeout of 0 -- input polling
|
||||
|
||||
echo abcde | read -t 0
|
||||
echo $?
|
||||
|
||||
read -t 0 < bash
|
||||
echo $?
|
||||
|
||||
read -t 0
|
||||
echo $?
|
||||
|
||||
|
||||
@@ -1,189 +0,0 @@
|
||||
: ${TMPDIR:=/tmp}
|
||||
|
||||
export LC_ALL=C
|
||||
export LANG=C
|
||||
|
||||
# catch-all for remaining untested redirection stuff
|
||||
set +o posix
|
||||
|
||||
echo abc > /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
set -o noclobber
|
||||
|
||||
#this should be an error
|
||||
echo def > /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
# but this should succeed
|
||||
echo def > /tmp/redir-test-2
|
||||
cat /tmp/redir-test-2
|
||||
|
||||
# and so should this
|
||||
echo def >| /tmp/redir-test
|
||||
cat /tmp/redir-test
|
||||
|
||||
set +o noclobber
|
||||
rm /tmp/redir-test /tmp/redir-test-2
|
||||
|
||||
# this should be an error
|
||||
z="a b"
|
||||
cat < $z
|
||||
|
||||
echo "Point 1"
|
||||
|
||||
exec 3</etc/passwd
|
||||
exec 4>$TMPDIR/bash-a
|
||||
exec 5>$TMPDIR/bash-b
|
||||
echo "Point 2"
|
||||
|
||||
echo to a 1>&4
|
||||
echo to b 1>&5
|
||||
cat $TMPDIR/bash-a
|
||||
cat $TMPDIR/bash-b
|
||||
exec 11</dev/null
|
||||
echo "Point 3"
|
||||
|
||||
echo to a 1>&4
|
||||
echo to b 1>&5
|
||||
cat $TMPDIR/bash-a
|
||||
cat $TMPDIR/bash-b
|
||||
|
||||
exec 11<&-
|
||||
echo "Point 4"
|
||||
|
||||
exec 6<>$TMPDIR/bash-c
|
||||
echo to c 1>&6
|
||||
cat $TMPDIR/bash-c
|
||||
echo "Point 5"
|
||||
|
||||
rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c
|
||||
|
||||
#
|
||||
# Test the effect of input buffering on the shell's input
|
||||
#
|
||||
${THIS_SH} < redir1.sub
|
||||
|
||||
# more open, close, duplicate file descriptors
|
||||
${THIS_SH} ./redir3.sub < ./redir3.in1
|
||||
|
||||
# still more redirections
|
||||
${THIS_SH} ./redir4.sub < redir4.in1
|
||||
|
||||
# various forms of null redirection
|
||||
testf()
|
||||
{
|
||||
if [ -f "$1" ]; then
|
||||
rm -f "$1"
|
||||
else
|
||||
echo oops -- $1 not found
|
||||
fi
|
||||
}
|
||||
|
||||
> $TMPDIR/null-redir-a
|
||||
testf $TMPDIR/null-redir-a
|
||||
|
||||
$EXIT > $TMPDIR/null-redir-b
|
||||
testf $TMPDIR/null-redir-b
|
||||
|
||||
( > $TMPDIR/null-redir-c )
|
||||
testf $TMPDIR/null-redir-c
|
||||
|
||||
$EXIT > $TMPDIR/null-redir-d &
|
||||
wait
|
||||
testf $TMPDIR/null-redir-d
|
||||
|
||||
exit 3 | $EXIT > $TMPDIR/null-redir-e
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
testf $TMPDIR/null-redir-e
|
||||
|
||||
exit 4 | > $TMPDIR/null-redir-f
|
||||
echo $? -- ${PIPESTATUS[@]}
|
||||
testf $TMPDIR/null-redir-f
|
||||
|
||||
> $TMPDIR/null-redir-g &
|
||||
wait
|
||||
testf $TMPDIR/null-redir-g
|
||||
|
||||
exec >$TMPDIR/null-redir-h &
|
||||
wait
|
||||
testf $TMPDIR/null-redir-h
|
||||
|
||||
# make sure async commands don't get /dev/null as stdin when an explicit
|
||||
# input redirection is supplied
|
||||
for x in 1 2 3; do
|
||||
{ read line ; echo $line ; } &
|
||||
wait
|
||||
{ read line ; echo $line ; } &
|
||||
wait
|
||||
done << EOF
|
||||
ab
|
||||
cd
|
||||
ef
|
||||
gh
|
||||
ij
|
||||
kl
|
||||
EOF
|
||||
|
||||
# make sure async commands get /dev/null as stdin in the absence of any
|
||||
# input redirection
|
||||
/bin/cat &
|
||||
wait
|
||||
echo $?
|
||||
|
||||
# make sure that loops work OK with here documents and are not run in
|
||||
# subshells
|
||||
while read line; do
|
||||
echo $line
|
||||
l2=$line
|
||||
done << EOF
|
||||
ab
|
||||
cd
|
||||
EOF
|
||||
echo $l2
|
||||
|
||||
# These should not echo anything -- bug in versions before 2.04
|
||||
( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1
|
||||
|
||||
( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 | cat
|
||||
|
||||
# in posix mode, non-interactive shells are not allowed to perform
|
||||
# filename expansion on input redirections, even if they expand to
|
||||
# a single filename
|
||||
set -o posix
|
||||
cat < redir1.*
|
||||
|
||||
# test ksh93 dup-and-close (move fd) redirections
|
||||
${THIS_SH} ./redir5.sub
|
||||
|
||||
# test behavior after a write error with a builtin command
|
||||
${THIS_SH} ./redir6.sub
|
||||
|
||||
# problem with redirections using fds bash uses internally
|
||||
: ${TMPDIR:=$TMPDIR}
|
||||
|
||||
trap 'rm -f $TMPDIR/bash-redir-$$' 0 1 2 3 6 15
|
||||
|
||||
echo before block
|
||||
{
|
||||
echo before redir
|
||||
exec 10>&1
|
||||
echo after redir
|
||||
} > $TMPDIR/bash-redir-$$
|
||||
|
||||
echo after block
|
||||
|
||||
${THIS_SH} ./redir7.sub
|
||||
|
||||
${THIS_SH} ./redir8.sub
|
||||
|
||||
exec 9>&2
|
||||
command exec 2>$TMPDIR/foo
|
||||
echo whatsis >&2
|
||||
echo cat $TMPDIR/foo
|
||||
cat $TMPDIR/foo
|
||||
rm -f $TMPDIR/foo
|
||||
exec 2>&9
|
||||
exec 9>&-
|
||||
|
||||
${THIS_SH} ./redir9.sub
|
||||
@@ -1,60 +0,0 @@
|
||||
rm -f u
|
||||
|
||||
${THIS_SH} -c 'exec 10>&1; echo fd 10 >&10' 10>u
|
||||
cat u
|
||||
rm -f u
|
||||
|
||||
${THIS_SH} -c 'exec 8>&1; echo fd 8 >&8' 8>u
|
||||
cat u
|
||||
rm -f u
|
||||
|
||||
exec 10>u
|
||||
exec 10>&1; echo 'fd 10' >&10
|
||||
cat u
|
||||
rm -f u
|
||||
exec 10>&-
|
||||
|
||||
exec 8>u
|
||||
exec 8>&1; echo 'fd 8' >&8
|
||||
cat u
|
||||
rm -f u
|
||||
exec 8>&-
|
||||
|
||||
rm -f infile
|
||||
cat > infile <<EOF
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
EOF
|
||||
|
||||
exec 7<&0
|
||||
exec 10<infile
|
||||
exec 0<&10; cat <&10
|
||||
exec 0<&7
|
||||
exec 7<&-
|
||||
|
||||
exec 7<&0
|
||||
exec 8<infile
|
||||
exec 0<&8 ; cat <&8
|
||||
exec 0<&7
|
||||
exec 7<&-
|
||||
|
||||
exec 7<&0
|
||||
exec 0</dev/null
|
||||
exec 10<infile
|
||||
exec 10<&0; cat <&10
|
||||
exec 0<&7
|
||||
exec 7<&-
|
||||
|
||||
exec 7<&0
|
||||
exec 0</dev/null
|
||||
exec 8<infile
|
||||
exec 8<&0; cat <&8
|
||||
exec 0<&7
|
||||
exec 7<&-
|
||||
|
||||
exit 0
|
||||
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
: ${TMPDIR:=/tmp}
|
||||
|
||||
func()
|
||||
{
|
||||
echo "to stdout"
|
||||
echo "to stderr" >&2
|
||||
}
|
||||
|
||||
rm -f $TMPDIR/foo
|
||||
|
||||
echo hey > $TMPDIR/foo
|
||||
func &>> $TMPDIR/foo
|
||||
|
||||
cat $TMPDIR/foo
|
||||
|
||||
echo
|
||||
func &> $TMPDIR/foo
|
||||
|
||||
cat $TMPDIR/foo
|
||||
|
||||
echo
|
||||
func >$TMPDIR/foo
|
||||
cat $TMPDIR/foo
|
||||
|
||||
echo
|
||||
echo hey > $TMPDIR/foo
|
||||
func >> $TMPDIR/foo
|
||||
cat $TMPDIR/foo
|
||||
|
||||
rm -f $TMPDIR/foo
|
||||
|
||||
logfunc()
|
||||
{
|
||||
echo "$@" &>> $TMPDIR/log
|
||||
}
|
||||
|
||||
type logfunc
|
||||
@@ -1,4 +0,0 @@
|
||||
echo "warning: all of these tests will fail if arrays have not" >&2
|
||||
echo "warning: been compiled into the shell" >&2
|
||||
${THIS_SH} ./array.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx array.right && rm -f /tmp/xx
|
||||
@@ -1,6 +0,0 @@
|
||||
echo "warning: all of these tests will fail if arrays have not" >&2
|
||||
echo "warning: been compiled into the shell" >&2
|
||||
echo "warning: the BASH_ARGC and BASH_ARGV tests will fail if debugging support" >&2
|
||||
echo "warning: has not been compiled into the shell" >&2
|
||||
${THIS_SH} ./array.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx array.right && rm -f /tmp/xx
|
||||
@@ -1,6 +0,0 @@
|
||||
echo "warning: some of these tests may fail if process substitution has not" >&2
|
||||
echo "warning: been compiled into the shell or if the OS does not provide" >&2
|
||||
ecoh "warning: /dev/fd." >&2
|
||||
|
||||
${THIS_SH} ./builtins.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx builtins.right && rm -f /tmp/xx
|
||||
@@ -1,6 +0,0 @@
|
||||
echo "warning: all of these tests will fail if arrays have not" >&2
|
||||
echo "warning: been compiled into the shell" >&2
|
||||
echo "warning: the BASH_ARGC and BASH_ARGV tests will fail if debugging support" >&2
|
||||
echo "warning: has not been compiled into the shell" >&2
|
||||
${THIS_SH} ./array.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx array.right && rm -f /tmp/xx
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./comsub.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx comsub.right && rm -f /tmp/xx
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./coproc.tests > /tmp/xx 2>&1
|
||||
diff /tmp/xx coproc.right && rm -f /tmp/xx
|
||||
@@ -1,2 +0,0 @@
|
||||
${THIS_SH} ./exp-tests | grep -v '^expect' > /tmp/xx
|
||||
diff /tmp/xx exp.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-0posix|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,4 +0,0 @@
|
||||
echo warning: some of these tests will fail if you do not have UTF-8 >&2
|
||||
echo warning: locales installed on your system
|
||||
${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > /tmp/xx
|
||||
diff /tmp/xx nquote4.right && rm -f /tmp/xx
|
||||
@@ -1,4 +0,0 @@
|
||||
echo warning: some of these tests will fail if you do not have UTF-8 >&2
|
||||
echo warning: locales installed on your system
|
||||
${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > /tmp/xx
|
||||
diff /tmp/xx nquote4.right && rm -f /tmp/xx
|
||||
@@ -1,84 +0,0 @@
|
||||
if : ; then
|
||||
set -e
|
||||
N=95
|
||||
while :; do
|
||||
# expr returns 1 if expression is null or 0
|
||||
set +e
|
||||
N_MOD_100=`expr $N % 100`
|
||||
set -e
|
||||
echo $N_MOD_100
|
||||
N=`expr $N + 1`
|
||||
if [ $N -eq 110 ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
set +e
|
||||
fi
|
||||
|
||||
(
|
||||
set -e
|
||||
false
|
||||
echo bad
|
||||
)
|
||||
echo $?
|
||||
|
||||
x=$(
|
||||
set -e
|
||||
false
|
||||
echo bad
|
||||
)
|
||||
echo $? $x
|
||||
|
||||
# command subst should not inherit -e
|
||||
set -e
|
||||
echo $(false; echo ok)
|
||||
|
||||
if set +e
|
||||
then
|
||||
false
|
||||
fi
|
||||
echo hi
|
||||
|
||||
set -e
|
||||
|
||||
# a failing command in the compound list following a while, until, or
|
||||
# if should not cause the shell to exit
|
||||
|
||||
while false; do
|
||||
echo hi
|
||||
done
|
||||
echo while succeeded
|
||||
|
||||
x=1
|
||||
until (( x == 4 )); do
|
||||
x=4
|
||||
done
|
||||
echo until succeeded: $x
|
||||
|
||||
if false; then
|
||||
echo oops
|
||||
fi
|
||||
echo if succeeded
|
||||
|
||||
# failing commands that are part of an AND or OR list should not
|
||||
# cause the shell to exit
|
||||
false && echo AND list failed
|
||||
echo AND list succeeded
|
||||
|
||||
false || echo OR list succeeded
|
||||
|
||||
! false
|
||||
echo ! succeeded
|
||||
|
||||
# make sure eval preserves the state of the -e flag and `!' reserved word
|
||||
set -e
|
||||
if eval false; then
|
||||
echo oops
|
||||
fi
|
||||
echo eval succeeded
|
||||
|
||||
! eval false
|
||||
echo ! eval succeeded -- 1
|
||||
|
||||
! eval '(exit 5)'
|
||||
echo ! eval succeeded -- 2
|
||||
@@ -1,45 +0,0 @@
|
||||
# subshell failure should cause the shell to exit silently
|
||||
${THIS_SH} -ce '(exit 17) ; echo "after (exit 17): $?"'
|
||||
|
||||
# pipeline failure should cause shell to exit silently
|
||||
${THIS_SH} -c 'set -e ; false | echo foo | while read x ; do ( exit 17 ) ; done; echo after pipeline subshell;'
|
||||
|
||||
# should be silent in posix mode
|
||||
${THIS_SH} -c 'set -o posix; set -e ; z=$(false;echo posix foo) ; echo $z'
|
||||
# but echo foo in non-posix
|
||||
${THIS_SH} -c 'set -e ; z=$(false;echo non-posix foo) ; echo $z'
|
||||
|
||||
${THIS_SH} -ce 'x=$(false) ; echo "x=\$(false) does not exit"'
|
||||
|
||||
${THIS_SH} -ce '{ false; echo false in brace group does not exit; }'
|
||||
echo after brace group failure: $?
|
||||
|
||||
set -e
|
||||
|
||||
! false
|
||||
echo after negation 1: $?
|
||||
|
||||
! false | false
|
||||
echo after negation 2: $?
|
||||
|
||||
! true
|
||||
echo after negation 3: $?
|
||||
|
||||
! (false)
|
||||
echo after negation 4: $?
|
||||
|
||||
{ false ; echo foo; } | cat
|
||||
echo after brace pipeline
|
||||
|
||||
false | echo foo | cat
|
||||
echo after failure 1
|
||||
|
||||
false | (echo foo; false) | true
|
||||
echo after failure 2
|
||||
|
||||
false | echo foo | while read x ; do ( exit 17 ) ; done | true
|
||||
echo after failure 3
|
||||
|
||||
# this pipeline failure should cause the shell to exit
|
||||
false | echo foo | false
|
||||
echo after failure 4
|
||||
@@ -1,86 +0,0 @@
|
||||
# test the trap code
|
||||
|
||||
trap 'echo exiting' 0
|
||||
trap 'echo aborting' 1 2 3 6 15
|
||||
|
||||
# make sure a user-specified subshell runs the exit trap, but does not
|
||||
# inherit the exit trap from a parent shell
|
||||
( trap 'echo subshell exit' 0; exit 0 )
|
||||
( exit 0 )
|
||||
|
||||
trap
|
||||
|
||||
func()
|
||||
{
|
||||
trap 'echo ${FUNCNAME:-$0}[$LINENO] funcdebug' DEBUG
|
||||
echo funcdebug line
|
||||
}
|
||||
|
||||
trap 'echo [$LINENO] debug' DEBUG
|
||||
echo debug line
|
||||
|
||||
trap
|
||||
|
||||
func
|
||||
|
||||
trap
|
||||
|
||||
trap 'echo ${FUNCNAME:-$0}[$LINENO] debug' DEBUG
|
||||
func2()
|
||||
{
|
||||
echo func2debug line
|
||||
}
|
||||
declare -ft func2
|
||||
func2
|
||||
|
||||
unset -f func2
|
||||
|
||||
trap '' DEBUG
|
||||
|
||||
trap
|
||||
|
||||
trap - debug
|
||||
|
||||
trap
|
||||
|
||||
trap - HUP
|
||||
trap hup
|
||||
trap '' INT
|
||||
trap '' int
|
||||
|
||||
trap
|
||||
|
||||
# exit 0 in exit trap should set exit status
|
||||
(
|
||||
set -e
|
||||
trap 'exit 0' EXIT
|
||||
false
|
||||
echo bad
|
||||
)
|
||||
echo $?
|
||||
|
||||
# hmmm...should this set the handling to SIG_IGN for children, too?
|
||||
trap '' USR2
|
||||
./trap1.sub
|
||||
|
||||
# test ERR trap
|
||||
./trap2.sub
|
||||
|
||||
#
|
||||
# show that setting a trap on SIGCHLD is not disastrous.
|
||||
#
|
||||
set -o monitor
|
||||
|
||||
trap 'echo caught a child death' SIGCHLD
|
||||
|
||||
sleep 7 & sleep 6 & sleep 5 &
|
||||
|
||||
wait
|
||||
|
||||
trap -p SIGCHLD
|
||||
|
||||
# Now reset some of the signals the shell handles specially back to
|
||||
# their default values (with or without the SIG prefix)
|
||||
trap - SIGINT QUIT TERM
|
||||
|
||||
trap
|
||||
@@ -1,89 +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
|
||||
Reference in New Issue
Block a user