mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Saw the previous revision :/ Made the sh-example even simpler
18
SC2031.md
18
SC2031.md
@@ -18,13 +18,23 @@ n=0
|
|||||||
while read i; do (( n+=i )); done < <(printf "%s\n" {1..10})
|
while read i; do (( n+=i )); done < <(printf "%s\n" {1..10})
|
||||||
echo $n
|
echo $n
|
||||||
```
|
```
|
||||||
In `sh`, temporary files, FIFOs or file descriptors can be used instead. When the output of the command can be stored to a variable before entering the loop, here documents are a preferable alternative:
|
In `sh`, temporary files, FIFOs or file descriptors can be used instead. When the output of the command can be stored to a variable before entering the loop, here documents are a preferable alternative.
|
||||||
```sh
|
```sh
|
||||||
n=0
|
n=0
|
||||||
SUMMANDS="$(printf '%s\n' 1 2 3 4 5 6 7 8 9 10)"
|
SUMMANDS="1
|
||||||
while read i; do n=$(( n + i )); done <<SUMMANDS_INPUT
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
6
|
||||||
|
7
|
||||||
|
8
|
||||||
|
9
|
||||||
|
10
|
||||||
|
"
|
||||||
|
while read i; do n=$(( n + i )); done <<SUMMANDS_HEREDOC_INPUT
|
||||||
$SUMMANDS
|
$SUMMANDS
|
||||||
SUMMANDS_INPUT
|
SUMMANDS_HEREDOC_INPUT
|
||||||
echo $n
|
echo $n
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user