I executed the following line:
which lsb_release 2&>1 /dev/null
Output:
error: no null in /dev
When I verified the error using the ls /dev/null
command, null
was present in /dev
. Why is this error occurring? I could not decipher the problem.
UPDATE
I just tried the above which
command on someone else's system, it worked perfectly without generating the error that I got.
Best Answer
First of all, redirections can occur anywhere in the command line, not necessarily at the end or start.
For example:
will save
foo bar
in the filespamegg
.Also, there are two versions of
which
, one is shell builtin and the other is external executable (comes withdebianutils
in Debian).In your command:
by
2&>1
, you are redirecting the STDERR (FD 2) to where STDOUT is (FD 1) pointed at, not to/dev/null
and this is done first.So the remaining command is:
As there is no command like
/dev/null
, hence the error.Note that, this behavior depends on whether
which
is a shell builtin or external executable,bash
,ksh
,dash
do not have a builtin and use externalwhich
and that simply ignores the error, does not show any error message.On the other hand,
zsh
uses a builtinwhich
and shows:So presumably, that specific error is shown by the builtin
which
of the shell you are using.Also, it seems you wanted to just redirect the STDERR to
/dev/null
iflsb_release
does not exist in thePATH
i.e.which
shows an error. If so, just redirect the STDERR to/dev/null
: