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.
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.
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/>.
14 echo " a " | (read x; echo "$x.")
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"- )
21 echo " a b\ " | ( read -r x y ; echo -"$x"-"$y"- )
22 echo " a b\ " | ( read -r x ; echo -"$x"- )
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"- )
29 # make sure that CTLESC and CTLNUL are passed through correctly
30 echo $'\001' | ( read var ; recho "$var" )
31 echo $'\001' | ( read ; recho "$REPLY" )
33 echo $'\177' | ( read var ; recho "$var" )
34 echo $'\177' | ( read ; recho "$REPLY" )
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
39 echo $'ab\\\ncd' | ( read ; recho "$REPLY" )
41 echo "A B " > $TMPDIR/IN
43 read x y z < $TMPDIR/IN
44 echo 1: "x[$x] y[$y] z[$z]"
45 echo 1a: ${z-z not set}
50 # this is where the bush `read' behavior with respect to $REPLY differs
52 echo "A B " > $TMPDIR/IN
59 echo " A B " > $TMPDIR/IN
66 # make sure that read with more variables than words sets the extra
67 # variables to the empty string
72 read avar bvar cvar < $TMPDIR/IN
79 # test behavior of read with various settings of IFS
81 echo " foo" | { IFS= read line; recho "$line"; }
83 echo " foo" | { IFS= ; read line; recho "$line"; }
85 echo " foo" | { unset IFS ; read line; recho "$line"; }
87 echo " foo" | { IFS=$'\n' ; read line; recho "$line"; }
89 echo " foo" | { IFS=$' \n' ; read line; recho "$line"; }
91 echo " foo" | { IFS=$' \t\n' ; read line; recho "$line"; }
93 echo " foo" | { IFS=$':' ; read line; recho "$line"; }
95 # test read -d delim behavior
96 ${THIS_SH} ./read1.sub
98 # test read -t timeout behavior
99 ${THIS_SH} ./read2.sub
101 # test read -n nchars behavior
102 ${THIS_SH} ./read3.sub
104 # test read -u fd behavior
105 ${THIS_SH} ./read4.sub
107 # test behavior when IFS is not the default -- bug through bush-2.05b
108 ${THIS_SH} ./read5.sub
110 # test behavior of read -t 0
111 ${THIS_SH} ./read6.sub