mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-16 08:30:49 +02:00
commit bash-20040311 snapshot
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
BUILD_DIR=/usr/local/build/chet/bash/bash-current
|
||||
BUILD_DIR=/usr/local/build/bash/bash-current
|
||||
THIS_SH=$BUILD_DIR/bash
|
||||
PATH=$PATH:$BUILD_DIR
|
||||
|
||||
|
||||
+54
-4
@@ -140,14 +140,64 @@ ok
|
||||
-7
|
||||
7
|
||||
7
|
||||
./arith1.sub: line 2: 4-- : syntax error: operand expected (error token is " ")
|
||||
./arith1.sub: line 3: 4++ : syntax error: operand expected (error token is " ")
|
||||
./arith1.sub: line 4: 4 -- : syntax error: operand expected (error token is " ")
|
||||
./arith1.sub: line 5: 4 ++ : syntax error: operand expected (error token is " ")
|
||||
1
|
||||
2
|
||||
1
|
||||
2
|
||||
6
|
||||
3
|
||||
7
|
||||
4
|
||||
0
|
||||
3
|
||||
7
|
||||
2
|
||||
-2
|
||||
1
|
||||
./arith1.sub: line 35: ((: ++ : syntax error: operand expected (error token is " ")
|
||||
7
|
||||
7
|
||||
./arith1.sub: line 38: ((: -- : syntax error: operand expected (error token is " ")
|
||||
7
|
||||
7
|
||||
7
|
||||
7
|
||||
1
|
||||
2
|
||||
1
|
||||
2
|
||||
1
|
||||
0
|
||||
5
|
||||
1
|
||||
6
|
||||
2
|
||||
3
|
||||
1
|
||||
4
|
||||
0
|
||||
./arith2.sub: line 33: ((: -- : syntax error: operand expected (error token is " ")
|
||||
-7
|
||||
-7
|
||||
./arith2.sub: line 37: ((: ++ : syntax error: operand expected (error token is " ")
|
||||
7
|
||||
7
|
||||
-7
|
||||
-7
|
||||
7
|
||||
7
|
||||
8 12
|
||||
./arith.tests: line 265: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
|
||||
./arith.tests: line 269: a b: syntax error in expression (error token is "b")
|
||||
./arith.tests: line 270: ((: a b: syntax error in expression (error token is "b")
|
||||
./arith.tests: line 268: ((: x=9 y=41 : syntax error in expression (error token is "y=41 ")
|
||||
./arith.tests: line 272: a b: syntax error in expression (error token is "b")
|
||||
./arith.tests: line 273: ((: a b: syntax error in expression (error token is "b")
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
42
|
||||
./arith.tests: line 281: b[c]d: syntax error in expression (error token is "d")
|
||||
./arith.tests: line 284: b[c]d: syntax error in expression (error token is "d")
|
||||
|
||||
@@ -254,6 +254,9 @@ echo $(( -7 ))
|
||||
echo $(( ++7 ))
|
||||
echo $(( --7 ))
|
||||
|
||||
${THIS_SH} ./arith1.sub
|
||||
${THIS_SH} ./arith2.sub
|
||||
|
||||
x=4
|
||||
y=7
|
||||
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
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 ))
|
||||
|
||||
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
|
||||
@@ -0,0 +1,38 @@
|
||||
# test of redone post-increment and post-decrement code
|
||||
echo $(( 4-- ))
|
||||
echo $(( 4++ ))
|
||||
echo $(( 4 -- ))
|
||||
echo $(( 4 ++ ))
|
||||
|
||||
(( array[0]++ ))
|
||||
echo ${array}
|
||||
|
||||
(( array[0] ++ ))
|
||||
echo ${array}
|
||||
|
||||
(( a++ ))
|
||||
echo $a
|
||||
(( a ++ ))
|
||||
echo $a
|
||||
|
||||
echo $(( a ++ + 4 ))
|
||||
echo $a
|
||||
|
||||
echo $(( a+++4 ))
|
||||
echo $a
|
||||
|
||||
echo $(( a---4 ))
|
||||
echo $a
|
||||
|
||||
echo $(( a -- + 4 ))
|
||||
echo $a
|
||||
|
||||
echo $(( a -- - 4 ))
|
||||
echo $a
|
||||
|
||||
(( ++ + 7 ))
|
||||
|
||||
(( ++ ))
|
||||
echo $(( +++7 ))
|
||||
echo $(( ++ + 7 ))
|
||||
(( -- ))
|
||||
@@ -0,0 +1,45 @@
|
||||
echo $(( --7 ))
|
||||
echo $(( ++7 ))
|
||||
echo $(( -- 7 ))
|
||||
echo $(( ++ 7 ))
|
||||
|
||||
((++array[0] ))
|
||||
echo $array
|
||||
(( ++ array[0] ))
|
||||
echo $array
|
||||
|
||||
(( ++a ))
|
||||
echo $a
|
||||
(( ++ a ))
|
||||
echo $a
|
||||
|
||||
(( --a ))
|
||||
echo $a
|
||||
(( -- a ))
|
||||
echo $a
|
||||
|
||||
echo $(( 4 + ++a ))
|
||||
echo $a
|
||||
|
||||
echo $(( 4+++a ))
|
||||
echo $a
|
||||
|
||||
echo $(( 4---a ))
|
||||
echo $a
|
||||
|
||||
echo $(( 4 - -- a ))
|
||||
echo $a
|
||||
|
||||
(( -- ))
|
||||
echo $(( ---7 ))
|
||||
echo $(( -- - 7 ))
|
||||
|
||||
(( ++ ))
|
||||
echo $(( ++7 ))
|
||||
echo $(( ++ + 7 ))
|
||||
|
||||
echo $(( ++-7 ))
|
||||
echo $(( ++ - 7 ))
|
||||
|
||||
echo $(( +--7 ))
|
||||
echo $(( -- + 7 ))
|
||||
@@ -215,4 +215,8 @@ ${THIS_SH} ./dollar-star1.sub
|
||||
# though bash-2.05b
|
||||
${THIS_SH} ./dollar-at1.sub
|
||||
|
||||
# tests for expansion of other variables in double-quoted strings containing
|
||||
# $@. Bugs through bash-2.05b
|
||||
${THIS_SH} ./dollar-at2.sub
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -211,4 +211,8 @@ esac
|
||||
# expansions -- bugs through bash-2.05b
|
||||
${THIS_SH} ./dollar-star1.sub
|
||||
|
||||
# tests for expansion of "$@" on rhs of things like ${param:+word}. Bugs
|
||||
# though bash-2.05b
|
||||
${THIS_SH} ./dollar-at1.sub
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
t1()
|
||||
{
|
||||
xxx="echo $@"
|
||||
|
||||
recho "$xxx ; echo $@"
|
||||
}
|
||||
|
||||
t2()
|
||||
{
|
||||
xxx="echo $@"
|
||||
|
||||
recho "${xxx} ; echo $@"
|
||||
}
|
||||
|
||||
t1 1
|
||||
t1 1 2
|
||||
|
||||
t2 1
|
||||
t2 1 2
|
||||
@@ -119,3 +119,9 @@ xa|xb|xc
|
||||
3
|
||||
3
|
||||
3
|
||||
argv[1] = <echo 1 ; echo 1>
|
||||
argv[1] = <echo 1 2 ; echo 1>
|
||||
argv[2] = <2>
|
||||
argv[1] = <echo 1 ; echo 1>
|
||||
argv[1] = <echo 1 2 ; echo 1>
|
||||
argv[2] = <2>
|
||||
|
||||
+3
-3
@@ -88,6 +88,7 @@ echo 'xwhix.h'
|
||||
xwhix.h
|
||||
echo 'xwhix.h'
|
||||
xwhix.h
|
||||
7 set -H
|
||||
8 echo line 2 for history
|
||||
9 echo a b c d e
|
||||
10 echo line 2 for history
|
||||
@@ -117,9 +118,8 @@ xwhix.h
|
||||
34 echo bar.c bar.o bar.html bar.h
|
||||
35 echo xbar.c xbar.o xbar.html xbar.h
|
||||
36 echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
37 echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
38 echo 'xwhix'
|
||||
39 echo 'xwhix.h'
|
||||
37 echo 'xwhix'
|
||||
38 echo 'xwhix.h'
|
||||
!!
|
||||
!!
|
||||
echo '!!' \!\!
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
echo $BASH_VERSION
|
||||
./histexp.tests: line 22: history: !!:z: history expansion failed
|
||||
1 for i in one two three; do echo $i; done
|
||||
2 /bin/sh -c 'echo this is $0'
|
||||
3 ls
|
||||
4 echo $BASH_VERSION
|
||||
1 for i in one two three; do echo $i; done
|
||||
2 /bin/sh -c 'echo this is $0'
|
||||
3 ls
|
||||
4 echo $BASH_VERSION
|
||||
5 HISTFILE=/tmp/newhistory
|
||||
6 echo line 2 for history
|
||||
echo line 2 for history
|
||||
echo line 2 for history
|
||||
set -H
|
||||
echo line 2 for history
|
||||
line 2 for history
|
||||
1 for i in one two three; do echo $i; done
|
||||
2 /bin/sh -c 'echo this is $0'
|
||||
3 ls
|
||||
4 echo $BASH_VERSION
|
||||
5 HISTFILE=/tmp/newhistory
|
||||
6 echo line 2 for history
|
||||
7 set -H
|
||||
8 echo line 2 for history
|
||||
a b c d e
|
||||
echo a b c d e
|
||||
a b c d e
|
||||
echo line 2 for history
|
||||
line 2 for history
|
||||
echo line 8 for history
|
||||
line 8 for history
|
||||
/bin/sh -c 'echo this is $0'
|
||||
this is /bin/sh
|
||||
echo sh
|
||||
sh
|
||||
echo /bin
|
||||
/bin
|
||||
echo e
|
||||
e
|
||||
a b c d e
|
||||
echo b c d e
|
||||
b c d e
|
||||
echo b c d
|
||||
b c d
|
||||
echo d e
|
||||
d e
|
||||
echo d e
|
||||
d e
|
||||
echo b c d
|
||||
b c d
|
||||
file.c
|
||||
echo file
|
||||
file
|
||||
echo .c
|
||||
.c
|
||||
echo 'file'
|
||||
file
|
||||
bax.c
|
||||
echo $file
|
||||
bax
|
||||
echo .c
|
||||
.c
|
||||
echo '$file'
|
||||
$file
|
||||
a b c d e
|
||||
echo 'a' 'b' 'c' 'd' 'e'
|
||||
a b c d e
|
||||
echo 'a b c d e'
|
||||
a b c d e
|
||||
foo.c foo.o foo.html foo.h
|
||||
echo bar.c foo.o foo.html foo.h
|
||||
bar.c foo.o foo.html foo.h
|
||||
echo bar.c bar.o bar.html bar.h
|
||||
bar.c bar.o bar.html bar.h
|
||||
echo xbar.c xbar.o xbar.html xbar.h
|
||||
xbar.c xbar.o xbar.html xbar.h
|
||||
echo xbar.c xbar.o xbar.html xbar.h
|
||||
xbar.c xbar.o xbar.html xbar.h
|
||||
echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
echo 'xwhix'
|
||||
xwhix
|
||||
echo 'xwhix.h'
|
||||
xwhix.h
|
||||
echo 'xwhix.h'
|
||||
xwhix.h
|
||||
echo 'xwhix.h'
|
||||
xwhix.h
|
||||
8 echo line 2 for history
|
||||
9 echo a b c d e
|
||||
10 echo line 2 for history
|
||||
11 echo line 8 for history
|
||||
12 /bin/sh -c 'echo this is $0'
|
||||
13 echo sh
|
||||
14 echo /bin
|
||||
15 echo e
|
||||
16 echo a b c d e
|
||||
17 echo b c d e
|
||||
18 echo b c d
|
||||
19 echo d e
|
||||
20 echo b c d
|
||||
21 echo file.c
|
||||
22 echo file
|
||||
23 echo .c
|
||||
24 echo 'file'
|
||||
25 echo $file.c
|
||||
26 echo $file
|
||||
27 echo .c
|
||||
28 echo '$file'
|
||||
29 echo a b c d e
|
||||
30 echo 'a' 'b' 'c' 'd' 'e'
|
||||
31 echo 'a b c d e'
|
||||
32 echo foo.c foo.o foo.html foo.h
|
||||
33 echo bar.c foo.o foo.html foo.h
|
||||
34 echo bar.c bar.o bar.html bar.h
|
||||
35 echo xbar.c xbar.o xbar.html xbar.h
|
||||
36 echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
37 echo xwhix.c xwhix.o xwhix.html xwhix.h
|
||||
38 echo 'xwhix'
|
||||
39 echo 'xwhix.h'
|
||||
!!
|
||||
!!
|
||||
echo '!!' \!\!
|
||||
!! !!
|
||||
ok 1
|
||||
ok 2
|
||||
ok 3
|
||||
@@ -49,3 +49,15 @@ while read -u 3 var
|
||||
do
|
||||
echo "$var"
|
||||
done 3<$0
|
||||
argv[1] = <>
|
||||
argv[1] = <>
|
||||
argv[1] = <:>
|
||||
argv[1] = <:>
|
||||
FOO
|
||||
argv[1] = <>
|
||||
argv[1] = <3>
|
||||
argv[1] = <>
|
||||
argv[2] = <>
|
||||
argv[3] = <>
|
||||
FOO
|
||||
0 0 0
|
||||
|
||||
@@ -90,3 +90,6 @@ ${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
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
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
|
||||
@@ -0,0 +1,36 @@
|
||||
IFS=: read x y z << EOF
|
||||
:::
|
||||
EOF
|
||||
recho $x
|
||||
recho "$x"
|
||||
recho $y
|
||||
recho "$y"
|
||||
recho $z
|
||||
recho "$z"
|
||||
|
||||
if [ -z "$x" ]; then
|
||||
echo FOO
|
||||
else
|
||||
echo BAR
|
||||
fi
|
||||
|
||||
IFS=: read -a A << EOF
|
||||
:::
|
||||
EOF
|
||||
|
||||
recho ${A[0]}
|
||||
recho "${A[0]}"
|
||||
|
||||
recho ${#A[@]}
|
||||
|
||||
recho "${A[@]}"
|
||||
|
||||
if [ -z "${A[0]}" ]; then
|
||||
echo FOO
|
||||
else
|
||||
echo BAR
|
||||
fi
|
||||
|
||||
echo -n ${A[0]} | cat -vet
|
||||
echo -n ${A[0]} | wc
|
||||
|
||||
Reference in New Issue
Block a user