mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Better explanation of the issue
@@ -16,9 +16,13 @@ read -r name
|
|||||||
|
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
By default, `read` will interpret backslashes before spaces and line feeds, and otherwise strip them. This is rarely expected or desired.
|
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, which is what `read -r` does. You should always use `-r` unless you have a good reason not to.
|
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`](https://www.tldp.org/LDP/abs/html/internal.html#READR) will still strip leading and trailing spaces. `IFS="" read -r` prevents this.
|
Note that [`read -r`](https://www.tldp.org/LDP/abs/html/internal.html#READR) will still strip leading and trailing spaces. `IFS="" read -r` prevents this.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user