2016-01-06 00:47:20 +03:00
|
|
|
# read
|
|
|
|
|
2016-01-26 12:52:58 +03:00
|
|
|
> BASH builtin for retrieving data from standard input.
|
2021-10-13 09:22:50 +03:00
|
|
|
> More information: <https://manned.org/read.1p>.
|
2016-01-06 00:47:20 +03: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 12:52:58 +03:00
|
|
|
`read -a {{array}}`
|
2016-01-06 00:47:20 +03:00
|
|
|
|
|
|
|
- Specify the number of maximum characters to be read:
|
|
|
|
|
2016-01-26 12:52:58 +03:00
|
|
|
`read -n {{character_count}} {{variable}}`
|
2016-01-06 00:47:20 +03:00
|
|
|
|
|
|
|
- Use a specific character as a delimiter instead of a new line:
|
2016-01-26 12:46:05 +03:00
|
|
|
|
2016-01-27 11:19:21 +03:00
|
|
|
`read -d {{new_delimiter}} {{variable}}`
|
2017-11-29 12:05:52 +03:00
|
|
|
|
|
|
|
- Do not let backslash (\) act as an escape character:
|
|
|
|
|
|
|
|
`read -r {{variable}}`
|
2019-01-23 16:37:43 +03:00
|
|
|
|
|
|
|
- Display a prompt before the input:
|
|
|
|
|
2020-10-04 20:33:38 +03:00
|
|
|
`read -p "{{Enter your input here: }}" {{variable}}`
|
2019-01-27 03:10:00 +03:00
|
|
|
|
|
|
|
- Do not echo typed characters (silent mode):
|
|
|
|
|
|
|
|
`read -s {{variable}}`
|
2021-02-13 23:03:16 +03:00
|
|
|
|
|
|
|
- Read stdin and perform an action on every line:
|
|
|
|
|
|
|
|
`while read line; do echo "$line"; done`
|