I have tried all sorts of ways to redirect both stdout and stderr to /dev/null without any success. I have almost my entire life run bash which I've never had this issue with, but for once in BSD I'm stuck with /bin/sh.
What I've tried:
if ls ./python* 2> /dev/null; then
echo found Python
fi
... which works; if Python is not present it will mute the error messages from ls.
However, if python.tgz is present, a line with be outputted which looks like this:
# ./test.sh
./python-2.7.3p1.tgz
I've tried:
if ls ./python* &> /dev/null; then
echo found Python
fi
and
if ls ./python* 2>1 > /dev/null; then
echo found Python
fi
and
if ls ./python* > /dev/null; then
echo found Python
fi
Nothing really works. I can only redirect one of the outputs, not both at the same time.
/bin/shhave implemented the&>/dev/nullsyntax, aparently not so or i have a older version (which i can't echo in any way, running OpenBSD 5.3 tho so should be sufficient) – Torxed Jun 25 '13 at 19:29shis based on pdksh. There's no more Bourne shell nowadays.cshintroduced>&also available inzsh.bashchose&>(now also supported byzshand somepdkshderivatives) though it clearly breaks POSIX compliance sincefoo &> fileis perfectly valid POSIX syntax which means something completely different. – Stéphane Chazelas Jun 25 '13 at 19:42foo &> fileis likefoo & > fileorfoo & : > file, that is run foo in background and open file for writing for no command at all (unlikely to be used like that). – Stéphane Chazelas Dec 09 '14 at 13:59>&was not specified in POSIX then it would make more sense for bash to choose this notation instead and be POSIX compliant. Do you see any way out of this mess? – Piotr Dobrogost Dec 09 '14 at 14:20>&is not ideal either as it conflicts with the>&2,>&-operators.zshadded it for convenience for csh users (csh doesn't have>&2). They're just syntactic sugar, just use> file 2>&1which is standard and portable (to Bourne-like shells). – Stéphane Chazelas Dec 09 '14 at 14:26&>shortcut, this works in Cygwin, which I'm stuck with. – Bill Naylor Oct 31 '20 at 12:10