|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Difference between ">/dev/null 2>&1" and "2>&1 >/dev/null"
Does >/dev/null 2>&1 and 2>&1 >/dev/null mean the same?
|
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Hi. They're not the same. In the first case, standard output is directed to a file (in this case /dev/null), and then standard error is directed to the same place (&1, or /dev/null). It's equivalent to Code:
> /dev/null 2> /dev/null In the second case, standard error is directed to where standard output is directed at the time (i.e. the screen), and then standard output is directed to somewhere else (/dev/null) Code:
$ cat Test echo stdout echo stderr >&2 $ ./Test > /dev/null 2>&1 $ $ ./Test 2>&1 > /dev/null stderr |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Then basically ">/dev/null 2>&1" and "&> /dev/null" do the same job i guess??
Last edited by proactiveaditya; 12-14-2009 at 08:50 AM.. |
|
#4
|
|||
|
|||
|
Quote:
Code:
&> /dev/null Works only in Bash FWIK. |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Code:
[root@wiki ~]# echo "1" &> /dev/null [root@wiki ~]# [root@wiki ~]# ech "1" &> /dev/null [root@wiki ~]# ">/dev/null 2>&1" and "&> /dev/null" does the same job |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Meaning of "> /dev/null 2>&1" | salanalani | Shell Programming and Scripting | 10 | 07-22-2008 03:29 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 12:52 AM |
| extran NUll character added after end of line "\n" | arunkumar_mca | UNIX for Dummies Questions & Answers | 1 | 11-12-2007 12:23 PM |
| what difference between "terminal" and "console" | chenhao_no1 | Programming | 1 | 09-09-2002 09:46 AM |
|
|