READ(1)
πΈ NAME πΈ
okay so welcome to READ(1) from fish-shell π β this is the fish builtin read, and yes bestie it does exactly what it says: read β read line of input into variables π
β¨
π¦ SYNOPSIS π¦
read [OPTIONS] [VARIABLE ...]
π DESCRIPTION π
NOTE: This page documents the fish builtinread. To see the documentation on any non-fish versions, usecommand man read. π«Ά
read reads from standard input and stores the result in shell variables. In an alternative mode, it can also print to its own standard output, for example for use in command substitutions. β¨
By default, read reads a single line and splits it into variables on spaces or tabs. Alternatively, a null character or a maximum number of characters can be used to terminate the input, and other delimiters can be given. π
Unlike other shells, there is no default variable (such as REPLY) for storing the result β instead, it is printed on standard output. no cap π
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. π―
If read sets a variable and you donβt specify a scope, it will use the same rules that set - display and change shell variables <> does β if the variable exists, it will use it (in the lowest scope). If it doesnβt, it will use an unexported function-scoped variable. π«‘
The following options, like the corresponding ones in set - display and change shell variables <>, control variable scope or attributes:
-U,--universalβ Sets a universal variable. The variable will be immediately available to all the userβs fish instances on the machine, and will be persisted across restarts of the shell. π-f,--functionβ Sets a variable scoped to the executing function. It is erased when the function ends. π§-l,--localβ Sets a locally-scoped variable in this block. It is erased when the block ends. Outside of a block, this is the same as--function. π-g,--globalβ Sets a globally-scoped variable. Global variables are available to all functions running in the same shell. They can be modified or erased. π-u,--unexportβ Prevents the variables from being exported to child processes (default behaviour). π-x,--exportβ Exports the variables to child processes. π₯
The following options control the interactive mode:
-c CMD,--command CMDβ Sets the initial string in the interactive mode command buffer toCMD. π¬-s,--silentβ Masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information. π-p,--prompt PROMPT_CMDβ Uses the output of the shell commandPROMPT_CMDas the prompt for the interactive mode. The default prompt command isset_color green; echo -n read; set_color --reset; echo -n "> "πΈ-P,--prompt-str PROMPT_STRβ Uses the literalPROMPT_STRas the prompt for the interactive mode. β¨-R,--right-prompt RIGHT_PROMPT_CMDβ Uses the output of the shell commandRIGHT_PROMPT_CMDas the right prompt for the interactive mode. There is no default right prompt command. π¦-S,--shellβ Enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode. NOTE: Prior to fish 3.0, the short opt for--shellwas-s, but it has been changed for compatibility with bashβs-sshort opt for--silent. π
The following options control how much is read and how it is stored:
-d,--delimiter DELIMITERβ Splits onDELIMITER.DELIMITERwill be used as an entire string to split on, not a set of characters. π-n,--nchars NCHARSβ Makesreadreturn after readingNCHARScharacters or the end of the line, whichever comes first. β-t,--tokenizeor--tokenize-rawβ Causesreadto split the input into variables by the shellβs tokenization rules. This means it will honor quotes and escaping. This option is of course incompatible with other options to control splitting like--delimiterand does not honorIFS <#envvar-IFS>(like fishβs tokenizer). The -t -or --tokenize variants perform quote removal, so e.g.a\ bis stored asa b. However variables and command substitutions are not expanded. π«Ά-a,--listβ Stores the result as a list in a single variable. This option is also available as--arrayfor backwards compatibility. π-z,--nullβ Marks the end of the line with the NUL character, instead of newline. This also disables interactive mode. π-L,--lineβ Reads each line into successive variables, and stops after each variable has been filled. This cannot be combined with the--nulloption, or options to control splitting like--delimiter. π―
Without the --line option, read reads a single line of input from standard input, breaks it into tokens, 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. π§
If no option to determine how to split like --delimiter, --line or --tokenize is given, the variable IFS is used as a list of characters to split on. Relying on the use of IFS is deprecated and this behaviour will be removed in future versions. The default value of IFS contains space, tab and newline characters. As a special case, if IFS is set to the empty string, each character of the input is considered a separate token. π
With the --line option, read reads a line of input from standard input into each provided variable, stopping when each variable has been filled. The line is not tokenized. π
If no variable names are provided, read enters a special case that provides redirection from standard input to standard output, useful for command substitution. For instance, the fish shell command below can be used to read a password from the console instead of hardcoding it in the command itself, which prevents it from showing up in fishβs history: π
mysql -uuser -p(read)
When running in this mode, read does not split the input in any way and text is redirected to standard output without any further processing or manipulation. β¨
If -l or --list is provided, only one variable name is allowed and the tokens are stored as a list in this variable. π
In order to protect the shell from consuming too many system resources, read will only consume a maximum of 100 MiB (104857600 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_limit <#envvar-fish_read_limit> variable. If set to 0 (zero), the limit is removed. β οΈ
π EXAMPLE π
read has a few separate uses. π
The following code stores the value 'hello' in the shell variable foo.
echo hello | read foo
The while <> command is a neat way to handle command output line-by-line:
printf '%s\n' line1 line2 line3 line4 | while read -l foo
echo "This is another line: $foo"
end
Delimiters given via "-d" are taken as one string:
echo a==b==c | read -d == -l a b c
echo $a # a
echo $b # b
echo $c # c
--tokenize honors quotes and escaping like the shellβs argument passing:
echo 'a\ b' | read -t first second
echo $first # outputs "a b", $second is empty
echo 'a"foo bar"b (command echo wurst)*" "{a,b}' | read -lt -l a b c
echo $a # outputs 'afoo barb' (without the quotes)
echo $b # outputs '(command echo wurst)* {a,b}' (without the quotes)
echo $c # nothing
For an example on interactive use, see Querying for user input <# user-input>. πΈ
π Copyright π
fish-shell developers π
okay thatβs the whole vibe, bestie β this was fish-shell READ(1), version 4.9, dated Sep 08, 2026. slay and stay hydrated π
β¨π«Ά
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms