From 6a42a6f55260f2bc316959665a16d951cc3ecb4a Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 14 Mar 2020 21:20:16 -0700 Subject: [PATCH] Updated SC2095 (markdown) --- SC2095.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SC2095.md b/SC2095.md index d232a5b..51a9444 100644 --- a/SC2095.md +++ b/SC2095.md @@ -1,6 +1,6 @@ -## Add < /dev/null to prevent ssh from swallowing stdin. +## Use ssh -n to prevent ssh from swallowing stdin. -The same error applies to multiple commands, like `ffmpeg` and `mplayer`. +The same error applies to multiple commands, like `ffmpeg -nostdin` and `mplayer -noconsolecontrols`. ### Problematic code: @@ -16,7 +16,7 @@ done < hosts.txt ```sh while read -r host do - ssh "$host" "uptime" < /dev/null + ssh -n "$host" "uptime" done < hosts.txt ``` ### Rationale: @@ -25,9 +25,9 @@ Commands that process stdin will compete with the `read` statement for input. Th The most common symptom of this is a `while read` loop only running once, even though the input contains many lines. This is because the rest of the lines are swallowed by the offending command. -To refuse such commands input, redirect their stdin with `< /dev/null`. +To refuse such commands input, you can use a command specific option like `ssh -n` or `ffmpeg -nostdin`. -You can also use command specific options like `ssh -n` and `mplayer -noconsolecontrols`. +More generally, you can also redirect their stdin with `< /dev/null`. This works for all commands with this behavior. ### Exceptions: