Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: fbc51c9ea7
Fetching contributors…

Cannot retrieve contributors at this time

113 lines (93 sloc) 1.897 kB
# Tests for the read builtin
# Tested elsewhere:
# reading from a coprocess A01grammar, A04redirect
# Not tested:
# -c/-l/-n (options for compctl functions)
# -q/-s (needs a tty)
read <<<'hello world'
print $REPLY
0:basic read command
>hello world
read -A <<<'hello world'
print $reply[2]
0:array read
read -k3 -u0 <<<foo:bar
print $REPLY
0:read specified number of chars
for char in y Y n N X $'\n'; do
read -q -u0 <<<$char
print $?
0:read yes or no, default no
read -d: <<<foo:bar
print $REPLY
0:read up to delimiter
print foo:bar|IFS=: read -A
print $reply
0:use different, IFS separator to array
>foo bar
print -z hello world; read -z
print $REPLY
0:read from editor buffer stack
>hello world
unset REPLY
read -E <<<hello
print $REPLY
0:read with echoing and assigning
unset REPLY
read -e <<<hello
print $REPLY
0:read with echoing but assigning disabled
read -e -t <<<hello
0:read with test first
read -e -t 5 <<<hello
print $SECONDS
0:read with timeout (no waiting should occur)
print -n 'Testing the\0null hypothesis\0' |
while read -d $'\0' line; do print $line; done
0:read with null delimiter
>Testing the
>null hypothesis
# Note that trailing NULLs are not stripped even if they are in
# $IFS; only whitespace characters contained in $IFS are stripped.
print -n $'Aaargh, I hate nulls.\0\0\0' | read line
print ${#line}
0:read with trailing metafied characters
(typeset -r foo
read foo) <<<bar
1:return status on failing to set parameter
?(eval):2: read-only variable: foo
read -AE array <<<'one two three'
print ${(j.:.)array}
0:Behaviour of -A and -E combination
read -Ae array <<<'four five six'
print ${(j.:.)array}
0:Behaviour of -A and -e combination
Jump to Line
Something went wrong with that request. Please try again.