-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC1012
wileyhy edited this page Oct 6, 2024
·
8 revisions
# Want tab
var=foo\tbar
or
# Want linefeed
var=foo\nbar
var="foo$(printf '\t')bar" # As suggested in warning
var="$(printf 'foo\tbar')" # Equivalent alternative
or
# Literal, quoted linefeed
line="foo
bar"
or
# Linefeed using ANSI-C quoting
line=$'foo\nbar'
ShellCheck has found a \t
, \n
or \r
in a context where they just become regular letters t
, n
or r
. Most likely, it was intended as a tab, linefeed or carriage return.
To generate such characters (plus other less common ones including \a
, \f
and octal escapes) , use printf
as in the example. The exception is for linefeeds that would be stripped by command substitution; in these cases, use a literal quoted linefeed instead.
Other characters like \z
generate a SC1001 info message, as the intent is less certain.
None.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!