1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
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"- )
# input ending in backslash
printf 'abc\' | { read var ; recho "$var"; }
printf 'abc\' | { read -r var ; recho "$var"; }
# 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 " > $TMPDIR/IN
unset x y z
read x y z < $TMPDIR/IN
echo 1: "x[$x] y[$y] z[$z]"
echo 1a: ${z-z not set}
read x < $TMPDIR/IN
echo 2: "x[$x]"
rm $TMPDIR/IN
# this is where the bash `read' behavior with respect to $REPLY differs
# from ksh93
echo "A B " > $TMPDIR/IN
read < $TMPDIR/IN
echo "[$REPLY]"
rm $TMPDIR/IN
echo " A B " > $TMPDIR/IN
read < $TMPDIR/IN
echo "[$REPLY]"
rm $TMPDIR/IN
# make sure that read with more variables than words sets the extra
# variables to the empty string
bvar=bvar
cvar=cvar
echo aa > $TMPDIR/IN
read avar bvar cvar < $TMPDIR/IN
echo =="$avar"==
echo =="$bvar"==
echo =="$cvar"==
rm $TMPDIR/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"; }
# this leaves `b' readonly
readonly b
read a b c <<EOF
a b c
EOF
# the latest POSIX draft says $? should be > 1
echo a = $a b = $b c = $c stat = $?
# 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
# test behavior when IFS is not the default -- bug through bash-2.05b
${THIS_SH} ./read5.sub
# test behavior of read -t 0
${THIS_SH} ./read6.sub
# test behavior of readline timeouts
${THIS_SH} ./read7.sub
# test behavior of read -n and read -d on regular files
${THIS_SH} ./read8.sub
# test behavior of trailing IFS whitespace - POSIX conformance
${THIS_SH} ./read9.sub
# test behavior of read builtin modifying $IFS
${THIS_SH} ./read10.sub
|