mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC1138 (markdown)
19
SC1138.md
19
SC1138.md
@@ -1,30 +1,19 @@
|
|||||||
## Shells are space sensitive. Use `< <(cmd)`, not `<< (cmd)`.
|
## Remove spaces between (( in arithmetic for loop.
|
||||||
|
|
||||||
### Problematic code:
|
### Problematic code:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
while read -r line
|
for( (i=0; i<10; i++) ); do echo $i; done
|
||||||
do
|
|
||||||
echo "You said: $line"
|
|
||||||
done <<(cmd)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Correct code:
|
### Correct code:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
while read -r line
|
for((i=0; i<10; i++)); do echo $i; done
|
||||||
do
|
|
||||||
echo "You said: $line"
|
|
||||||
done < <(cmd)
|
|
||||||
```
|
```
|
||||||
### Rationale:
|
### Rationale:
|
||||||
|
|
||||||
When redirecting `<` from a process substitution `<(cmd)`, make sure there is a space between the two `<` characters as shown in the example.
|
ShellCheck finds arithmetic for ((;;)) expressions where (( or )) are intervening with spaces
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
|
|
||||||
### Exceptions:
|
### Exceptions:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user