mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2312 (markdown)
11
SC2312.md
11
SC2312.md
@@ -18,6 +18,17 @@ dir="$(get_chroot_dir)"
|
||||
cd "$dir/etc"
|
||||
tar xf "$config"
|
||||
```
|
||||
|
||||
### Correct code: (with correction)
|
||||
|
||||
```sh
|
||||
set -e
|
||||
dir="$(get_chroot_dir)"
|
||||
[ -d "${dir}" ] || exit 1
|
||||
cd "$dir/etc"
|
||||
tar xf "$config"
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
In the problematic example, the exit code for `get_chroot_dir` is ignored because it is used in a command substitution in the argument of another command.
|
||||
|
Reference in New Issue
Block a user