Home > Software engineering >  What does "grep myname /etc/passwd >& /dev/null" mean?
What does "grep myname /etc/passwd >& /dev/null" mean?

Time:01-14

I saw this code in the example in shell scripting book.

case 1. grep myname /etc/passwd > /dev/null means grep myname in file /etc/passwd but no output to screen.

case 2. grep myname /etc/passwd >&2 means grep myname in file /etc/passwd and output to std err.

case 3. grep myname /etc/passwd >& /dev/null

What is the meaning of "&" right after redirection > in this case?

CodePudding user response:

In bash, it means both STDOUT and STDERR.

It's just like:

cmd >& file

is equivalent to

cmd >file 2>&1

but the former is bash and csh only

You have also a special bash syntax to pipe both STDERR and STDOUT:

<STDIN> |& <PROCESS STDOUT|STDERR>
  • Related