Skip to content

Files

Latest commit

 

History

History
29 lines (18 loc) · 675 Bytes

SC2162.md

File metadata and controls

29 lines (18 loc) · 675 Bytes

Pattern: Use of read without -r

Issue: -

Description

By default, read will interpret backslashes before spaces and line feeds, and otherwise strip them. 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.

Note that read -r will still strip leading and trailing spaces. IFS="" read -r prevents this.

Example of incorrect code:

echo "Enter name:"
read name

Example of correct code:

echo "Enter name:"
read -r name

Further Reading