-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
For bugs with existing features
- Rule Id: SC2154
- My shellcheck version (
shellcheck --version
or "online"): 0.11.0 - The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Shellcheck reports variable used in trap
statement is unassigned even if assigned earlier in the trap "script".
Here's a snippet or screenshot that shows the problem:
Mind the trap script is using single quotes - hence the variables are substituted during trap execution, not its declaration.
#!/usr/bin/env bash
trap 'exit_code=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $exit_code' ERR
#!/usr/bin/env bash
trap 'let exit_code=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $exit_code' ERR
#!/usr/bin/env bash
trap 'export exit_code=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $exit_code' ERR
Here's what shellcheck currently says:
trap 'export exit_code=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $exit_code' ERR
^-- SC2154 (warning): exit_code is referenced but not assigned.
Here's what I wanted or expected to see:
No errors 😎
Metadata
Metadata
Assignees
Labels
No labels