All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.shellcheck.rules.shellcheck.SC2095.html Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version

Add < /dev/null to prevent ssh from swallowing stdin.

The same error applies to multiple commands, like ffmpeg and mplayer.

Problematic code

while read -r host
do
  ssh "$host" "uptime"
done < hosts.txt

Correct code

while read -r host
do
  ssh "$host" "uptime" < /dev/null
done < hosts.txt

Rationale

Commands that process stdin will compete with the read statement for input. This is especially tricky for commands you wouldn't expect reads from stdin, like ssh .. uptime, ffmpeg and mplayer.

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.

You can also use command specific options like ssh -n and mplayer -noconsolecontrols.

Exceptions

None.

Related resources





© 2015 - 2025 Weber Informatics LLC | Privacy Policy