Pattern: Unnecessary escape in shell script
Issue: -
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')