2016-01-05 21:47:20 +00:00
|
|
|
# read
|
|
|
|
|
2016-01-26 09:52:58 +00:00
|
|
|
> BASH builtin for retrieving data from standard input.
|
2016-01-05 21:47:20 +00:00
|
|
|
|
|
|
|
- Store data that you type from the keyboard:
|
|
|
|
|
|
|
|
`read {{variable}}`
|
|
|
|
|
|
|
|
- Store each of the next lines you enter as values of an array:
|
|
|
|
|
2016-01-26 09:52:58 +00:00
|
|
|
`read -a {{array}}`
|
2016-01-05 21:47:20 +00:00
|
|
|
|
|
|
|
- Enable backspace and GNU readline hotkeys when entering input with read:
|
|
|
|
|
2016-01-26 09:52:58 +00:00
|
|
|
`read -e {{variable}}`
|
2016-01-05 21:47:20 +00:00
|
|
|
|
|
|
|
- Specify the number of maximum characters to be read:
|
|
|
|
|
2016-01-26 09:52:58 +00:00
|
|
|
`read -n {{character_count}} {{variable}}`
|
2016-01-05 21:47:20 +00:00
|
|
|
|
|
|
|
- Use a specific character as a delimiter instead of a new line:
|
2016-01-26 09:46:05 +00:00
|
|
|
|
2016-01-27 08:19:21 +00:00
|
|
|
`read -d {{new_delimiter}} {{variable}}`
|
2017-11-29 09:05:52 +00:00
|
|
|
|
|
|
|
- Do not let backslash (\) act as an escape character:
|
|
|
|
|
|
|
|
`read -r {{variable}}`
|
2019-01-23 13:37:43 +00:00
|
|
|
|
|
|
|
- Display a prompt before the input:
|
|
|
|
|
|
|
|
`read -p {{"Enter your input here: "}} {{variable}}`
|
2019-01-27 00:10:00 +00:00
|
|
|
|
|
|
|
- Do not echo typed characters (silent mode):
|
|
|
|
|
|
|
|
`read -s {{variable}}`
|