How can I store output in bash variable and suppress output to stderr and stdout? [duplicate]How do I suppress stderr warning messages from a command inside command substitution?bash: Use a variable to store stderr|stdout redirectionHow to capture ordered STDOUT/STDERR and add timestamp/prefixes?Pipe ssh's output (stderr and stdout) to different commandsRedirecting stdout and stderr still prints to stdoutredirect stdout and stderr in a bash scriptStore command output in variable when command includes pipesWhy is /dev/stderr invalid when redirecting to a pipe in cygwin?Where does stderr go to during boot (SysVinit)?How to suppress stdout / stderr from a shell script output?How to redirect stderr in a variable but keep stdout in the console
How do you conduct xenoanthropology after first contact?
Copycat chess is back
Why can't I see bouncing of a switch on an oscilloscope?
Motorized valve interfering with button?
Prevent a directory in /tmp from being deleted
What defenses are there against being summoned by the Gate spell?
New order #4: World
Infinite past with a beginning?
Are tax years 2016 & 2017 back taxes deductible for tax year 2018?
How to report a triplet of septets in NMR tabulation?
DOS, create pipe for stdin/stdout of command.com(or 4dos.com) in C or Batch?
I probably found a bug with the sudo apt install function
What makes Graph invariants so useful/important?
Should I join office cleaning event for free?
How can bays and straits be determined in a procedurally generated map?
Is there really no realistic way for a skeleton monster to move around without magic?
Can Medicine checks be used, with decent rolls, to completely mitigate the risk of death from ongoing damage?
A Journey Through Space and Time
least quadratic residue under GRH: an EXPLICIT bound
Download, install and reboot computer at night if needed
Japan - Plan around max visa duration
Is Social Media Science Fiction?
Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?
Patience, young "Padovan"
How can I store output in bash variable and suppress output to stderr and stdout? [duplicate]
How do I suppress stderr warning messages from a command inside command substitution?bash: Use a variable to store stderr|stdout redirectionHow to capture ordered STDOUT/STDERR and add timestamp/prefixes?Pipe ssh's output (stderr and stdout) to different commandsRedirecting stdout and stderr still prints to stdoutredirect stdout and stderr in a bash scriptStore command output in variable when command includes pipesWhy is /dev/stderr invalid when redirecting to a pipe in cygwin?Where does stderr go to during boot (SysVinit)?How to suppress stdout / stderr from a shell script output?How to redirect stderr in a variable but keep stdout in the console
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
How do I suppress stderr warning messages from a command inside command substitution?
3 answers
If i'm doing
oidvalue=$(snmpget -v 2c -c public localhost 1234)
This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I suppress stderr and stdout at the same time store in the variable?
Thanks
2nd EDIT: the below works for my condition:
oidvalue=$(snmpget -v 2c -c public localhost 1234) > /dev/null 2>&1
bash io-redirection stdout stderr
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by muru, Ulrich Schwarz, roaima, Prvt_Yadv, JigglyNaga 2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I suppress stderr warning messages from a command inside command substitution?
3 answers
If i'm doing
oidvalue=$(snmpget -v 2c -c public localhost 1234)
This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I suppress stderr and stdout at the same time store in the variable?
Thanks
2nd EDIT: the below works for my condition:
oidvalue=$(snmpget -v 2c -c public localhost 1234) > /dev/null 2>&1
bash io-redirection stdout stderr
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by muru, Ulrich Schwarz, roaima, Prvt_Yadv, JigglyNaga 2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the errorError: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.
– roaima
2 days ago
add a comment |
This question already has an answer here:
How do I suppress stderr warning messages from a command inside command substitution?
3 answers
If i'm doing
oidvalue=$(snmpget -v 2c -c public localhost 1234)
This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I suppress stderr and stdout at the same time store in the variable?
Thanks
2nd EDIT: the below works for my condition:
oidvalue=$(snmpget -v 2c -c public localhost 1234) > /dev/null 2>&1
bash io-redirection stdout stderr
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
This question already has an answer here:
How do I suppress stderr warning messages from a command inside command substitution?
3 answers
If i'm doing
oidvalue=$(snmpget -v 2c -c public localhost 1234)
This will store the output of that command in oidvalue, however as it is now, it will print some error to the screen. How can I suppress stderr and stdout at the same time store in the variable?
Thanks
2nd EDIT: the below works for my condition:
oidvalue=$(snmpget -v 2c -c public localhost 1234) > /dev/null 2>&1
This question already has an answer here:
How do I suppress stderr warning messages from a command inside command substitution?
3 answers
bash io-redirection stdout stderr
bash io-redirection stdout stderr
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
user3128077
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Apr 5 at 2:51
user3128077user3128077
11
11
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
user3128077 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
marked as duplicate by muru, Ulrich Schwarz, roaima, Prvt_Yadv, JigglyNaga 2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by muru, Ulrich Schwarz, roaima, Prvt_Yadv, JigglyNaga 2 days ago
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the errorError: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.
– roaima
2 days ago
add a comment |
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the errorError: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.
– roaima
2 days ago
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the error
Error: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.– roaima
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the error
Error: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.– roaima
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
If that command has no silent option, redirect error to /dev/null.
oidvalue=$(snmpget -v 2c -c public localhost 1234 2>/dev/null)
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If that command has no silent option, redirect error to /dev/null.
oidvalue=$(snmpget -v 2c -c public localhost 1234 2>/dev/null)
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
add a comment |
If that command has no silent option, redirect error to /dev/null.
oidvalue=$(snmpget -v 2c -c public localhost 1234 2>/dev/null)
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
add a comment |
If that command has no silent option, redirect error to /dev/null.
oidvalue=$(snmpget -v 2c -c public localhost 1234 2>/dev/null)
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
If that command has no silent option, redirect error to /dev/null.
oidvalue=$(snmpget -v 2c -c public localhost 1234 2>/dev/null)
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Apr 5 at 2:58
dedowsdidedowsdi
1943
1943
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
dedowsdi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
add a comment |
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
Thank you, but turns out what I needed was actually something like this, $(snmpget -v 2c -c public localhost 1234 2>&1 >/dev/null)
– user3128077
Apr 5 at 3:17
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
are you sure? this will set oidvalue to error message, stdout will be sucked by /dev/null . 2>&1 has no effect.
– dedowsdi
2 days ago
add a comment |
Your edit shows a command substitution that captures only the standard error stream of the command and discards the standard output stream completely.
– Kusalananda♦
2 days ago
For future reference, "it will print some error" is not nearly as useful as something like "it will print the error
Error: you didn't specify -f so I can't furble
." Remember that we can't see what you can see, so telling us everything is important. In your specific case, if you told us the error message we might be able to advise you how to avoid triggering it in the first place, rather than having to discard it.– roaima
2 days ago