using a pipe and avoiding the use of the stdin file descriptor

Akhil Jalagam
2023-08-22 20:06:33 +05:30
parent d0f0fc40a1
commit 9df8e616d9

@@ -30,6 +30,19 @@ uptime
EOF EOF
done < hosts.txt 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: ### Rationale: