read
shell builtinLinux/Unix
The read command is one of the most frequently used commands in Linux/Unix-like operating systems. read Read a line from standard input or a file descriptor
Quick Reference
Command Name:
read
Category:
shell builtin
Platform:
Linux/Unix
Basic Usage:
read [options] [arguments]
Common Use Cases
Syntax
read [options] [variable...]
Options
Option | Description |
---|---|
-a array |
Read words into the specified array variable, starting at index 0 |
-d delim |
Read until the first character of DELIM instead of newline |
-e |
Use Readline to obtain the line (enables command history and editing) |
-i text |
Use TEXT as the initial text for Readline |
-n nchars |
Read exactly NCHARS characters, if possible |
-N nchars |
Read exactly NCHARS characters, ignoring delimiter |
-p prompt |
Output the string PROMPT without a trailing newline before reading |
-r |
Backslash does not act as an escape character |
-s |
Do not echo input (useful for passwords) |
-t timeout |
Time out and return failure if a complete line is not read within TIMEOUT seconds |
-u fd |
Read from file descriptor FD instead of standard input |
Examples
How to Use These Examples
The examples below show common ways to use the read
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
read name