4 ms·
Shellcheck warns you about it: $ cat foo.sh #!/usr/bin/env bash set -euxo pipefail declare x="$(err)" $ shellcheck foo.sh In foo.sh line 3: de
by 0xbadcafebee 4y ago
Shellcheck warns you about it:
$ cat foo.sh
#!/usr/bin/env bash
set -euxo pipefail
declare x="$(err)"
$ shellcheck foo.sh
In foo.sh line 3:
declare x="$(err)"
^-- SC2034 (warning): x appears unused. Verify use (or export if used externally).
^-- SC2155 (warning): Declare and assign separately to avoid masking return values.
For more information:
https://www.shellcheck.net/wiki/SC2034 -- x appears unused. Verify use (or ...
https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
And the Bash man page mentions it a couple times, particularly around Pipelines, pipefail, Lists, and Compound Commands. You can also check exit status in the PIPESTATUS array.
I almost never use set -o pipefail, and often not even set -e. Your scripts end up failing for mysterious reasons and it takes forever to figure out which part of which pipeline failed. Instead, I simply check the result of the end of the pipe (did it return any data? does it look valid?) and that is good enough 99% of the time.