1#   This program is free software: you can redistribute it and/or modify
2#   it under the terms of the GNU General Public License as published by
3#   the Free Software Foundation, either version 3 of the License, or
4#   (at your option) any later version.
5#
6#   This program is distributed in the hope that it will be useful,
7#   but WITHOUT ANY WARRANTY; without even the implied warranty of
8#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9#   GNU General Public License for more details.
10#
11#   You should have received a copy of the GNU General Public License
12#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
13#
14echo " a " | (read x; echo "$x.")
15
16echo " a  b  " | ( read x y ; echo -"$x"-"$y"- )
17echo " a  b\ " | ( read x y ; echo -"$x"-"$y"- )
18echo " a  b  " | ( read x ; echo -"$x"- )
19echo " a  b\ " | ( read x ; echo -"$x"- )
20
21echo " a  b\ " | ( read -r x y ; echo -"$x"-"$y"- )
22echo " a  b\ " | ( read -r x ; echo -"$x"- )
23
24echo "\ a  b\ " | ( read -r x y ; echo -"$x"-"$y"- )
25echo "\ a  b\ " | ( read -r x ; echo -"$x"- )
26echo " \ a  b\ " | ( read -r x y ; echo -"$x"-"$y"- )
27echo " \ a  b\ " | ( read -r x ; echo -"$x"- )
28
29# make sure that CTLESC and CTLNUL are passed through correctly
30echo $'\001' | ( read var ; recho "$var" )
31echo $'\001' | ( read ; recho "$REPLY" )
32
33echo $'\177' | ( read var ; recho "$var" )
34echo $'\177' | ( read ; recho "$REPLY" )
35
36# make sure a backslash-quoted \\n still disappears from the input when
37# we're not reading in `raw' mode, and no stray CTLESC chars are left in
38# the input stream
39echo $'ab\\\ncd' | ( read ; recho "$REPLY" )
40
41echo "A B " > $TMPDIR/IN
42unset x y z
43read x y z < $TMPDIR/IN
44echo 1: "x[$x] y[$y] z[$z]"
45echo 1a: ${z-z not set}
46read x < $TMPDIR/IN
47echo 2: "x[$x]"
48rm $TMPDIR/IN
49
50# this is where the bash `read' behavior with respect to $REPLY differs
51# from ksh93
52echo "A B " > $TMPDIR/IN
53
54read < $TMPDIR/IN
55echo "[$REPLY]"
56
57rm $TMPDIR/IN
58
59echo " A B " > $TMPDIR/IN
60
61read < $TMPDIR/IN
62echo "[$REPLY]"
63
64rm $TMPDIR/IN
65
66# make sure that read with more variables than words sets the extra
67# variables to the empty string
68
69bvar=bvar
70cvar=cvar
71echo aa > $TMPDIR/IN
72read avar bvar cvar < $TMPDIR/IN
73echo =="$avar"==
74echo =="$bvar"==
75echo =="$cvar"==
76
77rm $TMPDIR/IN
78
79# test behavior of read with various settings of IFS
80
81echo " foo" | { IFS= read line; recho "$line"; }
82
83echo " foo" | { IFS= ; read line; recho "$line"; }
84
85echo " foo" | { unset IFS ; read line; recho "$line"; }
86
87echo " foo" | { IFS=$'\n' ; read line; recho "$line"; }
88
89echo " foo" | { IFS=$' \n' ; read line; recho "$line"; }
90
91echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
92
93echo " foo" | { IFS=$':' ; read line; recho "$line"; }
94
95# test read -d delim behavior
96${THIS_SH} ./read1.sub
97
98# test read -t timeout behavior
99${THIS_SH} ./read2.sub
100
101# test read -n nchars behavior
102${THIS_SH} ./read3.sub
103
104# test read -u fd behavior
105${THIS_SH} ./read4.sub
106
107# test behavior when IFS is not the default -- bug through bash-2.05b
108${THIS_SH} ./read5.sub
109
110# test behavior of read -t 0
111${THIS_SH} ./read6.sub
112