from bash man page:
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t
timeout] [-u fd] [name ...]
...blabla...
-t timeout
Cause read to time out and return failure if a complete line of input
(or a specified number of characters) is not read within timeout sec‐
onds. timeout may be a decimal number with a fractional portion follow‐
ing the decimal point. This option is only effective if read is reading
input from a terminal, pipe, or other special file; it has no effect
when reading from regular files. If read times out, read saves any par‐
tial input read into the specified variable name. If timeout is 0, read
returns immediately, without trying to read any data. The exit status
is 0 if input is available on the specified file descriptor, non-zero
otherwise. The exit status is greater than 128 if the timeout is
exceeded.
I expect read -r -t 1 VAL
will wait for my input, end with a enter, and save to $VAL.
Or if I type "wow" and do not press enter. read
will wait me 1s, and return with code >128.
Then [ $VAL == "wow" ] will be true.
But in my test, read just wait 1s, and ignore my input, and NOT set "partial input" to $VAL
[root tmp]# echo $BASH_VERSION
4.3.42(1)-release
[root tmp]# V=1
[root tmp]# echo $V
1
[root tmp]# IFS= read -t 1 -r V
wow[root tmp]# wow^C # <---- ???
[root tmp]# echo $?
142
[root tmp]# echo $V
# <---- ???
[root tmp]#
From man page, I think the result should be :
[root tmp]# echo $BASH_VERSION
4.3.42(1)-release
[root tmp]# V=1
[root tmp]# echo $V
1
[root tmp]# IFS= read -t 1 -r V
wow[root tmp]# ^C # <---- !!! read will "eat" my input
[root tmp]# echo $?
142
[root tmp]# echo $V
wow # <---- !!! and set V=`my partial input`
[root tmp]#
Do I misunderstood something? Why "wow" not store into $V ?
thx.