From a5557464718f809bd0faf7e28937ccfea1681656 Mon Sep 17 00:00:00 2001 From: TinCanTech Date: Fri, 7 Jan 2022 18:05:41 +0000 Subject: [PATCH] Updated SC2312 (markdown) --- SC2312.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/SC2312.md b/SC2312.md index 209cf83..6a2d421 100644 --- a/SC2312.md +++ b/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.