From ba18e924618a0a965f9057bc6696720b8b288c56 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 22 Aug 2021 20:05:48 -0700 Subject: [PATCH] Updated SC2304 (markdown) --- SC2304.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SC2304.md b/SC2304.md index 57f344c..d9ec920 100644 --- a/SC2304.md +++ b/SC2304.md @@ -17,6 +17,8 @@ result=$(expr 2 \* 3) ``` ### Rationale: +ShellCheck found an `expr` command whose operator is an unescaped asterisk `*`. + When using `expr`, each argument is expanded the same way as for any other command. This means that `expr 2 * 3` will turn into `expr 2 Desktop Documents Downloads Music Pictures 3` depending on the files in the current directory, causing an error like `expr: syntax error: unexpected argument ‘Desktop’` The best way to avoid this is to avoid `expr` and instead use `$((..))` instead. If you for any reason prefer the 200x slower, heavyweight process of forking a new process, you can escape the `*`. Both ways are demonstrated in the correct example.