mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Add an alternative for supporting
@@ -44,6 +44,14 @@ If the file has been written to when the pipeline is done, it means one of the c
|
||||
|
||||
This can obviously be extended with e.g. `echo "cmd1=$?" >> file` if the particular exit codes for particular commands are desired.
|
||||
|
||||
If `pipefail` or other options are used only as a sanity check, another option is to try the setting in a subshell and only apply it in the main shell if successful. This will set the flag on platforms where `sh` is linked to `ash`, `busybox`, or `bash`, but do nothing if `sh` is `dash`.
|
||||
|
||||
```sh
|
||||
# Set pipefail if it works in a subshell, disregard if unsupported
|
||||
# shellcheck disable=SC3040
|
||||
(set -o pipefail 2> /dev/null) && set -o pipefail
|
||||
```
|
||||
|
||||
Alternatively, switch to a shell that supports `pipefail`, such as Bash.
|
||||
|
||||
### Related resources:
|
||||
|
Reference in New Issue
Block a user