blob: fe27dae3ef0b7fd1cba7ebfae1c638977d3db700 [file] [log] [blame]
Jari Aaltoccc6cda1996-12-23 17:02:34 +00001echo " a " | (read x; echo "$x.")
2
3echo " a b " | ( read x y ; echo -"$x"-"$y"- )
4echo " a b\ " | ( read x y ; echo -"$x"-"$y"- )
5echo " a b " | ( read x ; echo -"$x"- )
6echo " a b\ " | ( read x ; echo -"$x"- )
7
8echo " a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
9echo " a b\ " | ( read -r x ; echo -"$x"- )
10
11echo "\ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
12echo "\ a b\ " | ( read -r x ; echo -"$x"- )
13echo " \ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
14echo " \ a b\ " | ( read -r x ; echo -"$x"- )
15
Jari Aaltocce855b1998-04-17 19:52:44 +000016# make sure that CTLESC and CTLNUL are passed through correctly
17echo $'\001' | ( read var ; recho "$var" )
18echo $'\001' | ( read ; recho "$REPLY" )
19
20echo $'\177' | ( read var ; recho "$var" )
21echo $'\177' | ( read ; recho "$REPLY" )
22
23# make sure a backslash-quoted \\n still disappears from the input when
24# we're not reading in `raw' mode, and no stray CTLESC chars are left in
25# the input stream
26echo $'ab\\\ncd' | ( read ; recho "$REPLY" )
27
Jari Aaltoccc6cda1996-12-23 17:02:34 +000028echo "A B " > /tmp/IN
29unset x y z
30read x y z < /tmp/IN
31echo 1: "x[$x] y[$y] z[$z]"
32echo 1a: ${z-z not set}
33read x < /tmp/IN
34echo 2: "x[$x]"
35rm /tmp/IN
36
Jari Aaltod166f041997-06-05 14:59:13 +000037# this is where the bash `read' behavior with respect to $REPLY differs
38# from ksh93
39echo "A B " > /tmp/IN
40
41read < /tmp/IN
42echo "[$REPLY]"
43
44rm /tmp/IN
45
46echo " A B " > /tmp/IN
47
48read < /tmp/IN
49echo "[$REPLY]"
50
51rm /tmp/IN
52
53# make sure that read with more variables than words sets the extra
54# variables to the empty string
55
56bvar=bvar
57cvar=cvar
58echo aa > /tmp/IN
59read avar bvar cvar < /tmp/IN
60echo =="$avar"==
61echo =="$bvar"==
62echo =="$cvar"==
63
64rm /tmp/IN
65
66# test behavior of read with various settings of IFS
67
68echo " foo" | { IFS= read line; recho "$line"; }
69
70echo " foo" | { IFS= ; read line; recho "$line"; }
71
72echo " foo" | { unset IFS ; read line; recho "$line"; }
73
74echo " foo" | { IFS=$'\n' ; read line; recho "$line"; }
75
76echo " foo" | { IFS=$' \n' ; read line; recho "$line"; }
77
78echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
79
80echo " foo" | { IFS=$':' ; read line; recho "$line"; }
Jari Aaltobb706242000-03-17 21:46:59 +000081
82# test read -d delim behavior
83${THIS_SH} ./read1.sub
84
85# test read -t timeout behavior
86${THIS_SH} ./read2.sub
87
88# test read -n nchars behavior
89${THIS_SH} ./read3.sub
Jari Aalto7117c2d2002-07-17 14:10:11 +000090
91# test read -u fd behavior
92${THIS_SH} ./read4.sub
Jari Aaltob80f6442004-07-27 13:29:18 +000093
94# test behavior when IFS is not the default -- bug through bash-2.05b
95${THIS_SH} ./read5.sub
Jari Aalto31859422009-01-12 13:36:28 +000096
97# test behavior of read -t 0
98${THIS_SH} ./read6.sub