mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2069 (markdown)
10
SC2069.md
10
SC2069.md
@@ -1,4 +1,4 @@
|
||||
## The order of the 2>&1 and the redirect matters. The 2>&1 has to be last.
|
||||
## To redirect stdout+stderr, 2>&1 must be last (or use '{ cmd > file; } 2>&1' to clarify).
|
||||
|
||||
### Problematic code:
|
||||
|
||||
@@ -14,7 +14,7 @@ firefox > /dev/null 2>&1
|
||||
|
||||
### Rationale:
|
||||
|
||||
Redirections are handled in order.
|
||||
When it comes to redirection, order matters.
|
||||
|
||||
The problematic code means "Point stderr to where stdout is currently pointing (the terminal). Then point stdout to /dev/null".
|
||||
|
||||
@@ -24,7 +24,11 @@ In other words, the problematic code hides stdout and shows stderr. The correct
|
||||
|
||||
### Exceptions
|
||||
|
||||
If you want stderr as stdout and stdout to a file, you can ignore this message.
|
||||
If you actually do want to redirect stdout to a file, and then turn stderr into the new stdout, you can make this more explicit with braces:
|
||||
|
||||
{ firefox > /dev/null; } 2>&1
|
||||
|
||||
Also note that this warning does not trigger when output is piped or captured.
|
||||
|
||||
### Related resources:
|
||||
|
||||
|
Reference in New Issue
Block a user