I found this to get user input from the command line. But it is failing into recognizing the new line characters I put into the input. Doing:
#!/bin/bash
read -e -p "Multiline input=" variable;
printf "'variable=%s'" "${variable}";
- Typing
'multi\nline'
onMultiline input=
makesprintf
output'variable=multinline'
- Typing
'multi\\nline'
onMultiline input=
makesprintf
output'variable=multi\nline'
How printf
can print the new line I read by read -p
, i.e., output
multi
line
Instead of multinline
or multi\nline
?
Related questions:
- What does the -p option do in the read command?
- bash: read: how to capture '\n' (newline) character?
- shell: read: differentiate between EOF and newline
- https://stackoverflow.com/questions/4296108/how-do-i-add-a-line-break-for-read-command
- Read arguments separated by newline
- https://stackoverflow.com/questions/43190306/how-to-add-new-line-after-user-input-in-shell-scripting
-r
for the read command. – glenn jackman Jun 27 '19 at 10:50help read
into your interactive shell. – glenn jackman Jun 27 '19 at 14:19