What does '2>' and '&>' mean in Bash?

Asked

Viewed 398 times

15

I’m starting to study Bash and while analyzing some codes on Github, I came across the following excerpts for creating a Heme:

which rbenv &> /dev/null || return
$(node -v 2> /dev/null)

1 answer

14


which rbenv &> /dev/null || return
$(node -v 2> /dev/null)

The which get the path of rbenv and redirects the stdout and stderr for /dev/null with &>, or || returns the execution of node -v and redirects to stderr, 2>.

Where:

  • which: Get the path to a file.
  • &: Symbol used to specify a file descriptor, when there is no descriptor, redirects to stdout and stderr.
  • >: Used to make the redirect.
  • /dev/null: Where it will be redirected, in this case the black hole.
  • 2>: Redirects error messages to /dev/null.

For more information TLDP - I/O Redirection.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.