]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/read.tests
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / read.tests
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 #
14 echo " a " | (read x; echo "$x.")
15
16 echo " a b " | ( read x y ; echo -"$x"-"$y"- )
17 echo " a b\ " | ( read x y ; echo -"$x"-"$y"- )
18 echo " a b " | ( read x ; echo -"$x"- )
19 echo " a b\ " | ( read x ; echo -"$x"- )
20
21 echo " a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
22 echo " a b\ " | ( read -r x ; echo -"$x"- )
23
24 echo "\ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
25 echo "\ a b\ " | ( read -r x ; echo -"$x"- )
26 echo " \ a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
27 echo " \ a b\ " | ( read -r x ; echo -"$x"- )
28
29 # make sure that CTLESC and CTLNUL are passed through correctly
30 echo $'\001' | ( read var ; recho "$var" )
31 echo $'\001' | ( read ; recho "$REPLY" )
32
33 echo $'\177' | ( read var ; recho "$var" )
34 echo $'\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
39 echo $'ab\\\ncd' | ( read ; recho "$REPLY" )
40
41 echo "A B " > $TMPDIR/IN
42 unset x y z
43 read x y z < $TMPDIR/IN
44 echo 1: "x[$x] y[$y] z[$z]"
45 echo 1a: ${z-z not set}
46 read x < $TMPDIR/IN
47 echo 2: "x[$x]"
48 rm $TMPDIR/IN
49
50 # this is where the bash `read' behavior with respect to $REPLY differs
51 # from ksh93
52 echo "A B " > $TMPDIR/IN
53
54 read < $TMPDIR/IN
55 echo "[$REPLY]"
56
57 rm $TMPDIR/IN
58
59 echo " A B " > $TMPDIR/IN
60
61 read < $TMPDIR/IN
62 echo "[$REPLY]"
63
64 rm $TMPDIR/IN
65
66 # make sure that read with more variables than words sets the extra
67 # variables to the empty string
68
69 bvar=bvar
70 cvar=cvar
71 echo aa > $TMPDIR/IN
72 read avar bvar cvar < $TMPDIR/IN
73 echo =="$avar"==
74 echo =="$bvar"==
75 echo =="$cvar"==
76
77 rm $TMPDIR/IN
78
79 # test behavior of read with various settings of IFS
80
81 echo " foo" | { IFS= read line; recho "$line"; }
82
83 echo " foo" | { IFS= ; read line; recho "$line"; }
84
85 echo " foo" | { unset IFS ; read line; recho "$line"; }
86
87 echo " foo" | { IFS=$'\n' ; read line; recho "$line"; }
88
89 echo " foo" | { IFS=$' \n' ; read line; recho "$line"; }
90
91 echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
92
93 echo " 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
113 # test behavior of readline timeouts
114 ${THIS_SH} ./read7.sub
115
116 # test behavior of read -n and read -d on regular files
117 ${THIS_SH} ./read8.sub