mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
using a pipe and avoiding the use of the stdin file descriptor
13
SC2095.md
13
SC2095.md
@@ -30,6 +30,19 @@ uptime
|
||||
EOF
|
||||
done < hosts.txt
|
||||
```
|
||||
or
|
||||
|
||||
By using a pipe and avoiding the use of the stdin file descriptor, this ensures that commands in the loop are not interfered with.
|
||||
|
||||
```sh
|
||||
exec 3< hosts.txt
|
||||
while read -r host
|
||||
do
|
||||
ssh "$host" "uptime"
|
||||
done <&3
|
||||
# Close the file descriptor
|
||||
exec 3<&-
|
||||
```
|
||||
|
||||
### Rationale:
|
||||
|
||||
|
Reference in New Issue
Block a user