From 659bfd31dcd702086a733ab792bfc2bd7b643349 Mon Sep 17 00:00:00 2001 From: Rushen Wang <45029442+dovics@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:57:35 +0800 Subject: [PATCH] Updated SC1138 (markdown) --- SC1138.md | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/SC1138.md b/SC1138.md index 5a24c50..c15f1c2 100644 --- a/SC1138.md +++ b/SC1138.md @@ -1,30 +1,19 @@ -## Shells are space sensitive. Use `< <(cmd)`, not `<< (cmd)`. +## Remove spaces between (( in arithmetic for loop. ### Problematic code: ```sh -while read -r line -do - echo "You said: $line" -done <<(cmd) +for( (i=0; i<10; i++) ); do echo $i; done ``` ### Correct code: ```sh -while read -r line -do - echo "You said: $line" -done < <(cmd) +for((i=0; i<10; i++)); do echo $i; done ``` ### Rationale: -When redirecting `<` from a process substitution `<(cmd)`, make sure there is a space between the two `<` characters as shown in the example. - -With a space `cmd1 < <(cmd2)`, is correctly interpreted as "run cmd1, reading stdin from cmd2, without forking for a pipeline". - -Without a space, `<<` is incorrectly considered a here document, and `(cmd2)` is an invalid delimiter token. - +ShellCheck finds arithmetic for ((;;)) expressions where (( or )) are intervening with spaces ### Exceptions: