hush: use ash's read builtin

function                                             old     new   delta
shell_builtin_read                                     -    1000   +1000
set_local_var_from_halves                              -      24     +24
setvar2                                                -       7      +7
...
popstring                                            140     134      -6
ash_main                                            1375    1368      -7
setvar                                               184     174     -10
arith_set_local_var                                   36       -     -36
builtin_read                                        1096     185    -911
------------------------------------------------------------------------------
(add/remove: 3/1 grow/shrink: 5/23 up/down: 1038/-1007)        Total: 31 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2010-01-12 23:29:57 +01:00
parent 045f4ad92c
commit 03dad22f8a
18 changed files with 124 additions and 49 deletions

View File

@ -0,0 +1,5 @@
test 1: | abc1 def |
test 2: | \abc2 d\ef |
test 3: |abc3 def|
test 4: |\abc4 d\ef|
Done

View File

@ -0,0 +1,5 @@
echo ' \abc1 d\ef ' | ( read ; echo "test 1: |$REPLY|" )
echo ' \abc2 d\ef ' | ( read -r ; echo "test 2: |$REPLY|" )
echo ' \abc3 d\ef ' | ( read REPLY; echo "test 3: |$REPLY|" )
echo ' \abc4 d\ef ' | ( read -r REPLY; echo "test 4: |$REPLY|" )
echo Done

View File

@ -0,0 +1,10 @@
test 1: .a. .b. .c.
test 2: .a. .b. .c.
test 3: .a. .. .b,c.
test 4: .a. .. .b,c.
test 5: .a. .. .c.
test 6: .a. .. .c. .d.
test 7: .a. .. .b,c,d , ,.
test 8: .. .a. .b. .c.
test 9: .a. .b. .c. ..
test A: .. .a. .. .b. .c.

View File

@ -0,0 +1,10 @@
printf 'a\t\tb\tc\n' | ( IFS=$(printf "\t") read a b c; echo "test 1: .$a. .$b. .$c." )
printf 'a\t\tb\tc\n' | ( IFS=$(printf " \t") read a b c; echo "test 2: .$a. .$b. .$c." )
printf 'a,,b,c\n' | ( IFS="," read a b c; echo "test 3: .$a. .$b. .$c." )
printf 'a,,b,c\n' | ( IFS=" ," read a b c; echo "test 4: .$a. .$b. .$c." )
printf 'a ,, c\n' | ( IFS=" ," read a b c; echo "test 5: .$a. .$b. .$c." )
printf 'a ,, c d\n' | ( IFS=" ," read a b c d; echo "test 6: .$a. .$b. .$c. .$d." )
printf ' a,,b,c,d , ,\n' | ( IFS=" ," read a b c; echo "test 7: .$a. .$b. .$c." )
printf '\t,\ta\t,\tb\tc' | ( IFS=$(printf " \t,") read a b c d; echo "test 8: .$a. .$b. .$c. .$d." )
printf '\t\ta\t,\tb\tc' | ( IFS=$(printf " \t,") read a b c d; echo "test 9: .$a. .$b. .$c. .$d." )
printf '\t,\ta\t,,\tb\tc' | ( IFS=$(printf " \t,") read a b c d e; echo "test A: .$a. .$b. .$c. .$d. .$e." )

View File

@ -0,0 +1,3 @@
test
tes
tes

View File

@ -0,0 +1,3 @@
echo 'test' | (read reply; echo "$reply")
echo 'test' | (read -n 3 reply; echo "$reply")
echo 'test' | (read -n3 reply; echo "$reply")

View File

@ -0,0 +1,2 @@
testbest
test\

View File

@ -0,0 +1,2 @@
echo -e 'test\\\nbest' | (read reply; echo "$reply")
echo -e 'test\\\nbest' | (read -r reply; echo "$reply")

View File

@ -0,0 +1,4 @@
><
><
>test<
>test<

View File

@ -0,0 +1,10 @@
# bash 3.2 outputs:
# ><
{ echo -n 'te'; sleep 2; echo 'st'; } | (read -t 1 reply; echo ">$reply<")
# ><
{ sleep 2; echo 'test'; } | (read -t 1 reply; echo ">$reply<")
# >test<
{ echo -n 'te'; sleep 1; echo 'st'; } | (read -t 2 reply; echo ">$reply<")
# >test<
{ sleep 1; echo 'test'; } | (read -t 2 reply; echo ">$reply<")