which-bugs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stderr redirect


From: kalle
Subject: stderr redirect
Date: Sun, 4 Dec 2022 09:50:26 +0100

Hi,
I do not know if this is a bug - so I do not know if I'm asking in the right place. But let me explain what I'm trying to do.

I want to check if a program exist and if not test for another program like this:
which yay || which pacman

If yay does no exists I get:
yay not found
to stdout with an error code of 1

which means that if can't redirect stderr to null
prog=$(which yay 2>/dev/null || which pacman)
So if yay does not exist prog becomes:
yay not found
/sbin/pacman

This is not the case if I for example do: ls non_existant_file, that results in:
ls: cannot access 'non_existant_file': No such file or directory
to stderr with error code of 2 and it's possible for me to do: ls non_existant_file 2>/dev/null
with an empty result.

So my question is, should which push it's error message to stderr instead? Or is the implementation as it should be?

Best regards,
Ka le


reply via email to

[Prev in Thread] Current Thread [Next in Thread]