diff --git a/doc_src/read.txt b/doc_src/read.txt index fa176c004..64a0d01c8 100644 --- a/doc_src/read.txt +++ b/doc_src/read.txt @@ -7,7 +7,10 @@ read [OPTIONS] VARIABLES... \subsection read-description Description -`read` reads from standard input and stores the result in one or more shell variables. By default it reads one line terminated by a newline but options are available to read up to a null character and to limit each "line" to a maximum number of characters. At least one variable name must be given. This command does not default to populating a var named `REPLY` like other shells do. +`read` reads from standard input and stores the result in one or more shell variables. By default, +one line (terminated by a newline) is read into each variable. Alternatively, a null character or a +maximum number of characters can be used to terminate the input. Unlike other shells, there is no +default variable (such as `REPLY`) for storing the result. The following options are available: @@ -21,7 +24,8 @@ The following options are available: - `-l` or `--local` makes the variables local. -- `-n NCHARS` or `--nchars=NCHARS` causes `read` to return after reading NCHARS characters rather than waiting for a complete line of input (either newline or null terminated). +- `-n NCHARS` or `--nchars=NCHARS` makes `read` return after reading NCHARS characters or the end of + the line, whichever comes first. - `-p PROMPT_CMD` or `--prompt=PROMPT_CMD` uses the output of the shell command `PROMPT_CMD` as the prompt for the interactive mode. The default prompt command is set_color green; echo read; set_color normal; echo "> ". @@ -39,7 +43,8 @@ The following options are available: - `-a` or `--array` stores the result as an array in a single variable. -- `-z` or `--null` reads up to NUL instead of newline. Disables interactive mode. +- `-z` or `--null` marks the end of the line with the NUL character, instead of newline. This also + disables interactive mode. `read` reads a single line of input from stdin, breaks it into tokens based on the delimiter set via `-d`/`--delimiter` as a complete string (like `string split` or, if that has not been given the (deprecated) `IFS` shell variable as a set of characters, and then assigns one token to each variable specified in `VARIABLES`. If there are more tokens than variables, the complete remainder is assigned to the last variable. As a special case, if `IFS` is set to the empty string, each character of the input is considered a separate token. @@ -47,9 +52,13 @@ If `-a` or `--array` is provided, only one variable name is allowed and the toke See the documentation for `set` for more details on the scoping rules for variables. -When read reaches the end-of-file (EOF) instead of the separator, it sets `$status` to 1. If not, it sets it to 0. +When `read` reaches the end-of-file (EOF) instead of the terminator, the exit status is set to 1. +Otherwise, it is set to 0. -Fish has a default limit of 10 MiB on the number of characters each `read` will consume. If you attempt to read more than that `$status` is set to 122 and the variable will be empty. You can modify that limit by setting the `FISH_READ_BYTE_LIMIT` variable at any time including in the environment before fish starts running. If you set it to zero then no limit is imposed. This is a safety mechanism to keep the shell from consuming an unreasonable amount of memory if the input is malformed. Note that this limit also affects how much data a command substitution is allowed to output. +In order to protect the shell from consuming too many system resources, `read` will only consume a +maximum of 10 MiB (1048576 bytes); if the terminator is not reached before this limit then VARIABLE +is set to empty and the exit status is set to 122. This limit can be altered with the +`FISH_READ_BYTE_LIMIT` variable. If set to 0 (zero), the limit is removed. \subsection read-history Using another read history file