Shell on the study notes> / dev / null 2> & 1 Comments

 

shell may often see:> / dev / null 2> & 1

The result of the command output can be defined by a%> form

Decomposition this combination: "> / dev / null 2> & 1" for the five parts.

# 1:> Representative where to redirect, for example: echo "123"> /home/123.txt 

# 2: / dev / null file representative of an empty device

# 3: 2> indicates the standard error stderr

# 4: & meant to be equivalent to means, 2> & 1, 2 indicates an output equivalent to a redirection

# 5: 1 indicates stdout standard output, the system default value is 1, the "> / dev / null" is equivalent to "1> / dev / null"

 

# Therefore,> / dev / null 2> & 1 can also be written as "1> / dev / null 2 > & 1"

 

Then the execution of the sentence for the title of this article:

# . 1> / dev / null: first standard output redirection device to an empty file, i.e. does not output any information to the terminal, it means no information is displayed. 
# 2> & 1: Next, redirect the standard error output to standard output, because before the standard output device has been redirected to an empty file, it can redirect the standard error output device to an empty file.

 

Guess you like

Origin www.cnblogs.com/JetpropelledSnake/p/11118830.html