Skip to content

Files

Latest commit

 

History

History
33 lines (20 loc) · 695 Bytes

SC2028.md

File metadata and controls

33 lines (20 loc) · 695 Bytes

Pattern: Use of echo with escape sequence

Issue: -

Description

Backslash escapes like \t and \n are not expanded by echo, and become literal backslash-t, backslash-n.

printf does expand these sequences, and should be used instead.

Other, non-portable methods include echo -e '\t' and echo $'\t'. This rule will warn if this is used in a script with shebang #!/bin/sh.

If you actually wanted a literal backslash-t, use

echo "\\t"

Example of incorrect code:

echo "Name:\t$value"

Example of correct code:

printf "Name:\t%s\n" "$value"

Further Reading