Reputation: 1450
I am using package-name -v
to see if the output contains "command not found". If the output does contains "command not found", I have to do something like that:
#!/bin/bash
bml_check="$(bml -v)"
echo $bml_check
The value of bml_check
is always showing empty. Can someone help with this?
Upvotes: 2
Views: 528
Reputation: 659
That is because only stdout
is saved on the variable, not stderr
.
You have to save both in the variable instead:
#!/bin/bash
bml_check="$(bml -v 2>&1)"
echo "bml_check -> $bml_check"
Will produce:
bml_check -> file.sh: line 2: bml: command not found
Upvotes: 1