1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/read.md

36 lines
762 B
Markdown
Raw Normal View History

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