Implement new read --null flag

The `--null` flag to `read` makes it split incoming lines on NUL instead
of newlines. This is intended for processing the output of a command
that uses NUL separators (such as `find -print0`).

Fixes #1694.
This commit is contained in:
Kevin Ballard
2014-09-21 19:18:56 -07:00
parent f889ad0fda
commit 8f8c4cdd17
8 changed files with 192 additions and 43 deletions

View File

@@ -1,3 +1,4 @@
# vim: set filetype=fish:
#
# Test read builtin and IFS
#
@@ -35,6 +36,8 @@ echo '' | read -l one two
print_vars one two
echo 'test' | read -l one two three
print_vars one two three
echo 'foo bar baz' | read -l one two three
print_vars one two three
echo
set -l IFS
@@ -91,3 +94,25 @@ echo $foo
echo $bar
echo 'test' | read -n 1 foo
echo $foo
# read -0 tests
echo
echo '# read -z tests'
echo -n 'testing' | read -lz foo
echo $foo
echo -n 'test ing' | read -lz foo
echo $foo
echo 'newline' | read -lz foo
echo $foo
echo -n 'test ing' | read -lz foo bar
print_vars foo bar
echo -ne 'test\0ing' | read -lz foo bar
print_vars foo bar
echo -ne 'foo\nbar' | read -lz foo bar
print_vars foo bar
echo -ne 'foo\nbar\0baz\nquux' | while read -lza foo
print_vars foo
end
true

View File

@@ -16,6 +16,7 @@ two
1 ''
1 '' 1 ''
1 'test' 1 '' 1 ''
1 'foo' 1 'bar' 1 ' baz'
1 'hello'
1 'h' 1 'ello'
@@ -42,3 +43,14 @@ test
tes
tin
t
# read -z tests
testing
test ing
newline
1 'test' 1 'ing'
1 'test' 1 ''
1 'foo' 1 'bar'
2 'foo' 'bar'
2 'baz' 'quux'