mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2095 (markdown)
10
SC2095.md
10
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:
|
### Problematic code:
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ done < hosts.txt
|
|||||||
```sh
|
```sh
|
||||||
while read -r host
|
while read -r host
|
||||||
do
|
do
|
||||||
ssh "$host" "uptime" < /dev/null
|
ssh -n "$host" "uptime"
|
||||||
done < hosts.txt
|
done < hosts.txt
|
||||||
```
|
```
|
||||||
### Rationale:
|
### 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.
|
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:
|
### Exceptions:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user