When the read built-in's '-n' option is used to limit the number of characters read, backslashes should only be counted if the '-r' option is also suppiled. This matches how bash behaves.
function old new delta shell_builtin_read 1360 1358 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Ron Yorston <r...@pobox.com> --- shell/ash_test/ash-read/read_n.right | 2 ++ shell/ash_test/ash-read/read_n.tests | 2 ++ shell/hush_test/hush-read/read_n.right | 2 ++ shell/hush_test/hush-read/read_n.tests | 2 ++ shell/shell_common.c | 2 +- 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/shell/ash_test/ash-read/read_n.right b/shell/ash_test/ash-read/read_n.right index 1f81af0bc..bd29f8ca3 100644 --- a/shell/ash_test/ash-read/read_n.right +++ b/shell/ash_test/ash-read/read_n.right @@ -1,3 +1,5 @@ test tes tes +12 +\1 diff --git a/shell/ash_test/ash-read/read_n.tests b/shell/ash_test/ash-read/read_n.tests index 12423ba6e..fde3d8954 100755 --- a/shell/ash_test/ash-read/read_n.tests +++ b/shell/ash_test/ash-read/read_n.tests @@ -1,3 +1,5 @@ echo 'test' | (read reply; echo "$reply") echo 'test' | (read -n 3 reply; echo "$reply") echo 'test' | (read -n3 reply; echo "$reply") +echo '\1\2' | (read -n 2 reply; echo "$reply") +echo '\1\2' | (read -r -n 2 reply; echo "$reply") diff --git a/shell/hush_test/hush-read/read_n.right b/shell/hush_test/hush-read/read_n.right index 1f81af0bc..bd29f8ca3 100644 --- a/shell/hush_test/hush-read/read_n.right +++ b/shell/hush_test/hush-read/read_n.right @@ -1,3 +1,5 @@ test tes tes +12 +\1 diff --git a/shell/hush_test/hush-read/read_n.tests b/shell/hush_test/hush-read/read_n.tests index 12423ba6e..fde3d8954 100755 --- a/shell/hush_test/hush-read/read_n.tests +++ b/shell/hush_test/hush-read/read_n.tests @@ -1,3 +1,5 @@ echo 'test' | (read reply; echo "$reply") echo 'test' | (read -n 3 reply; echo "$reply") echo 'test' | (read -n3 reply; echo "$reply") +echo '\1\2' | (read -n 2 reply; echo "$reply") +echo '\1\2' | (read -r -n 2 reply; echo "$reply") diff --git a/shell/shell_common.c b/shell/shell_common.c index 754fef34b..839da02e6 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -279,7 +279,7 @@ shell_builtin_read(struct builtin_read_params *params) } put: bufpos++; - } while (--nchars); + } while (backslash || --nchars); if (argv[0]) { /* Remove trailing space $IFS chars */ -- 2.50.1 _______________________________________________ busybox mailing list busybox@busybox.net https://lists.busybox.net/mailman/listinfo/busybox