commands:builtin:read

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
commands:builtin:read [2013/04/14 12:31]
thebonsai Don't tread version 4 special - it has been around for a long time now
commands:builtin:read [2020/06/27 08:35] (current)
thebonsai -e works with -u since 5.1 alpha
Line 4: Line 4:
 ===== Synopsis ===== ===== Synopsis =====
 <​code>​ <​code>​
-read [-ers] [-u <FD>] [-t <​TIMEOUT>​] [-p <​PROMPT>​] [-a <​ARRAY>​] [-n <​NCHARS>​] [-d <​DELIM>​] [-i <​TEXT>​] [<​NAME...>​]+read [-ers] [-u <FD>] [-t <​TIMEOUT>​] [-p <​PROMPT>​] [-a <​ARRAY>​] [-n <​NCHARS>​] [-N <​NCHARS>​] [-d <​DELIM>​] [-i <​TEXT>​] [<​NAME...>​]
 </​code>​ </​code>​
  
Line 29: Line 29:
 while IFS= read -r; do while IFS= read -r; do
   line=$REPLY   line=$REPLY
 +  ...
 +done < text.txt
 +</​code>​
 +
 +Alternately,​ you can enclose $REPLY in double quotes and avoid fiddling with IFS altogether:
 +
 +<​code>​
 +while read -r; do
 +  line="​$REPLY"​
   ...   ...
 done < text.txt done < text.txt
Line 42: Line 51:
 |''​-a <​ARRAY>''​|read the data word-wise into the specified array ''<​ARRAY>''​ instead of normal variables| |''​-a <​ARRAY>''​|read the data word-wise into the specified array ''<​ARRAY>''​ instead of normal variables|
 |''​-d <​DELIM>''​|recognize ''<​DELIM>''​ as data-end, rather than ''<​newline>''​| |''​-d <​DELIM>''​|recognize ''<​DELIM>''​ as data-end, rather than ''<​newline>''​|
-|''​-e''​|on interactive shells: use Bash's readline interface to read the data|+|''​-e''​|on interactive shells: use Bash's readline interface to read the data. Since version 5.1-alpha, this can also be used on specified file descriptors using ''​-u''​|
 |''​-i <​STRING>''​|preloads the input buffer with text from ''<​STRING>'',​ only works when Readline (''​-e''​) is used| |''​-i <​STRING>''​|preloads the input buffer with text from ''<​STRING>'',​ only works when Readline (''​-e''​) is used|
 |''​-n <​NCHARS>''​|reads ''<​NCHARS>''​ characters of input, then quits| |''​-n <​NCHARS>''​|reads ''<​NCHARS>''​ characters of input, then quits|
  • commands/builtin/read.1365942699.txt
  • Last modified: 2013/04/14 12:31
  • by thebonsai