-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2162
Alesiani Marco edited this page Oct 18, 2021
·
11 revisions
echo "Enter name:"
read name
echo "Enter name:"
read -r name
By default, read
will interpret backslashes before spaces and line feeds (i.e. you can use backslashes in your string as an escape character). This is rarely expected or desired.
Normally you just want to read data including backslashes which are part of the input string and have no special escape meaning, which is what read -r
does. You should always use -r
unless you have a good reason not to:
-r
If this option is given, backslash does not act as an escape character.
Note that read -r
will still strip leading and trailing spaces. IFS="" read -r
prevents this.
If you want backslashes to affect field splitting and line terminators instead of being read, you can disable this message with a directive.