Skip to content

Latest commit

 

History

History
39 lines (24 loc) · 807 Bytes

SC1001.md

File metadata and controls

39 lines (24 loc) · 807 Bytes

Pattern: Unnecessary escape in shell script

Issue: -

Description

You have escaped something that has no special meaning when escaped. The backslash will be simply be ignored.

If the backslash was supposed to be literal, single quote or escape it.

If you wanted it to expand to something, rewrite the expression. For linefeeds (\n), put them literally in quotes. For other characters, use POSIX printf or bash/ksh $'...'.

Example of incorrect code:

# Want literal backslash
echo Yay \o/

# Want linefeed
greeting=Hello\nWorld

# Want other characters
carriagereturn=\r

Example of correct code:

echo 'Yay \o/'

greeting='Hello
World'

carriagereturn=$(printf '\r')

Further Reading