Linux Shell standard output and standard error output specified order and impact

# First direct standard error output 2 to standard output 1,

# At this time, standard output 1 points to the console, so standard error output 2 points to the console,

# After that, point standard output 1 to the file /tmp/t.txt, but standard error output 2 still points to the console.

ls non_exists 2> & 1> /tmp/t.txt # So, the error message is printed on the screen,

ls: cannot access non_exists: No such file or directory

cat /tmp/t.txt # There is no content in /tmp/t.txt.

 

# First point the standard output 1 to the file /tmp/t.txt,

# Then point standard error output 2 to standard output 1,

# This way both standard error output 2 and standard output 1 point to the file /tmp/t.txt

ls non_exists> /tmp/t.txt 2> & 1 # The error message no longer appears on the screen,

cat /tmp/t.txt # Error messages are saved in the file /tmp/t.txt

ls: cannot access non_exists: No such file or directory

 

Published 27 original articles · praised 4 · visits 9690

Guess you like

Origin blog.csdn.net/yoshubom/article/details/104630299