diff options
author | Kevin Ballard <kevin@sb.org> | 2014-07-13 22:36:26 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-07-14 00:46:38 -0700 |
commit | 973dd6ffbdc189f22b634de0d684e92a9c160c9d (patch) | |
tree | 242487f472926817ac2b805fad0f68b169aee76e /doc_src/read.txt | |
parent | 72e8489d50d749c86d5b57609bb0c4d83a03b41a (diff) |
read: Support arrays, character splitting
Enhance the `read` builtin to support creating an array with the --array
flag. With --array, only a single variable name is allowed and the
entire input is tokenized and placed into that variable as an array.
Also add custom behavior if IFS is empty or unset. In that event, split
the input on every character, instead of the previous behavior of doing
no splitting at all.
Diffstat (limited to 'doc_src/read.txt')
-rw-r--r-- | doc_src/read.txt | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/doc_src/read.txt b/doc_src/read.txt index ca7a4d14..4f1760a5 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -19,11 +19,17 @@ The following options are available: - <code>-u</code> or <code>--unexport</code> prevents the variables from being exported to child processes (default behaviour). - <code>-U</code> or <code>--universal</code> causes the specified shell variable to be made universal. - <code>-x</code> or <code>--export</code> exports the variables to child processes. +- <code>-a</code> or <code>--array</code> stores the result as an array. \c read reads a single line of input from stdin, breaks it into tokens based on the <tt>IFS</tt> shell variable, and then assigns one token to each variable specified in <tt>VARIABLES</tt>. If there are more tokens than variables, the complete remainder is assigned to the last variable. +As a special case, if \c IFS is set to the empty string, each character of the +input is considered a separate token. + +If \c -a or \c --array is provided, only one variable name is allowed and the +tokens are stored as an array in this variable. See the documentation for \c set for more details on the scoping rules for variables. |