mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2069 (markdown)
22
SC2069.md
22
SC2069.md
@@ -1 +1,21 @@
|
||||
The order of the 2>&1 and the redirect matters. The 2>&1 has to be last.
|
||||
## The order of the 2>&1 and the redirect matters. The 2>&1 has to be last.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
firefox 2>&1 > /dev/null
|
||||
|
||||
### Correct code:
|
||||
|
||||
firefox > /dev/null 2>&1
|
||||
|
||||
### Rationale:
|
||||
|
||||
Redirections are handled in order.
|
||||
|
||||
The problematic code means "Point stderr to where stdout is currently pointing (the terminal). Then point stdout to /dev/null".
|
||||
|
||||
The correct code means "Point stdout to /dev/null. Then point stderr to where stdout is currently pointing (/dev/null).".
|
||||
|
||||
### Contraindications
|
||||
|
||||
If you want stderr as stdout and stdout to a file, you can ignore this message.
|
Reference in New Issue
Block a user