0

I found my Linux command doesn't work,Which confused me a lot.Here is it.

Test Case

root@ajinlong:/var# cat test.txt 
dsv vm 1
test
dsv vm 2
# No Output
root@ajinlong:/var# cat test.txt | grep "dsv" 2&>/dev/null

# No Output
root@ajinlong:/var# cat test.txt | grep "dsv" 1>/dev/null 2>&1

root@ajinlong:/var# cat test.txt | grep dsv
dsv vm 1
dsv vm 2

It seem 2&>/dev/null equal to 1>/dev/null 2>&1.I haven't seen the Usage .

Coderon
  • 475
  • 4
  • 6
  • 2
    One thing to note about this question not addressed in the linked question: bash does not have a `2&>file` [redirection](https://www.gnu.org/software/bash/manual/bash.html#Redirections). `&>file` **is** a valid redirection (both stdout and stderr redirected to the file), so the `2` will be used _as an argument to the command_. If you do `cat test.txt | grep "dsv" 2` then you'll probably get a "2: no such file" error. The redirection to /dev/null discards the error message, "hiding" the problematic bash code. You'd only uncover the problem by examining grep's exit status – glenn jackman Sep 14 '22 at 16:59

0 Answers0