From 9df8e616d9c924b97d1ab6326b17a00d56d20f91 Mon Sep 17 00:00:00 2001 From: Akhil Jalagam Date: Tue, 22 Aug 2023 20:06:33 +0530 Subject: [PATCH] using a pipe and avoiding the use of the stdin file descriptor --- SC2095.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SC2095.md b/SC2095.md index afea4ed..0fd3a55 100644 --- a/SC2095.md +++ b/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: