Nagireddy Hanisha
Nagireddy Hanisha

Reputation: 1450

Check if package installed

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

Answers (1)

M. Becerra
M. Becerra

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

Related Questions