From 5ec5f4a8a7f26bcecdf4cbd2e599b561a97c9e00 Mon Sep 17 00:00:00 2001 From: koalaman Date: Thu, 20 Nov 2014 12:14:13 -0800 Subject: [PATCH] Updated SC2069 (markdown) --- SC2069.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/SC2069.md b/SC2069.md index 1a140f2..125e33f 100644 --- a/SC2069.md +++ b/SC2069.md @@ -1 +1,21 @@ -The order of the 2>&1 and the redirect matters. The 2>&1 has to be last. \ No newline at end of file +## 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. \ No newline at end of file