forked from koalaman/shellcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
SC2155
Vidar Holen edited this page Oct 4, 2015
·
3 revisions
export foo="$(mycmd)"
export foo
foo=$(mycmd)
In the original code, the return value of mycmd
is ignored, and export
will instead always return true. This may prevent conditionals, set -e
and traps from working correctly.
When first marked for export and assigned separately, the return value of the assignment will be that of mycmd
. This avoids the problem.
If you intend to ignore the return value of an assignment, you can either ignore this warning or use
export foo
foo=$(mycmd) || true
Shellcheck does not warn about export foo=bar
because bar
is a literal and not a command substitution with an independent return value. It also does not warn about local -r foo=$(cmd)
, where declaration and assignment must be in the same command.