So I found this answer and it didn't work for me. Couldn't find anything else.
Using >nul in a variable
What I'm trying to do is prevent output when setting a variable like this.
var=$(/bin/command.out)
If the command doesn't produce an error, then there's no problem. But if it does, it prints it all out to the terminal. I tried adding this, but it just seems to get ignored.
var=$(/bin/command.out) > /dev/null
I've treid putting everything to the right of the = in quotes. I've tried doing the escape character like that guy suggested. No luck.
Thanks.
just realized that link was for batch. I'm working in bash just so that's clear.
You need
var=$(/bin/command.out 2> /dev/null)
E.g.
$ var=$(not_a_command 2> /dev/null)
$ echo $var
$(uname 2> /dev/null)
$ echo $var
Linux
There are two outputs in Linux:
1> (commonly called STDOUT) which is the output2> (called STDERR) which is the error output.It was the error output which was writing the message.
You can find more details from the following chapter of the "Advanced Bash-Scripting Guide":
Chapter 20. I/O Redirection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With