Quote:
Originally Posted by berndbausch
Remove the square brackets and you should be fine.
Explanation: whatever comes between the if and the semicolon is executed and evaluated. A value of 0 is interpreted as TRUE and the then branch will be entered.
|
Yes, you are right.
Code:
printf "Confirm if GPG Keys are installed... \n"
if rpm -q gpg-pubkey 2>&1 > /dev/null ; then
printf "GPG Keys rpms are installed \n"
else "GPG Keys need to be installed \n"
fi
That code works, however some of the other examples that I've seen online refers to bash [[ conditional construct and using $<( command goes here )>
https://digitalvectorz.wordpress.com...ator-expected/
Example
Code:
if [[ rpm -q gpg-pubkey 2>&1 > /dev/null ]]; then
printf "GPG Keys rpm are installed \n"
else "GPG Keys need to be installed \n"
fi
It blows up with the following:
Code:
./rpm_test2.sh
Confirm if GPG Keys are installed...
./rpm_test2.sh: line 6: conditional binary operator expected
./rpm_test2.sh: line 6: syntax error `-q'
./rpm_test2.sh: line 6: `if [[ rpm -q gpg-pubkey 2>&1 > /dev/null ]]; then'
...so let me ask this...how do I set the rpm query output to appear in the then statement? I've added a variable...however I don't know...
Code:
printf "Confirm if GPG Keys are installed... \n"
rpm_version=$
if rpm -q gpg-pubkey 2>&1 > /dev/null ; then
printf "GPG Keys rpms are installed $rpm_version \n"
else "GPG Keys need to be installed"
fi
Code:
./rpm_test.sh
Confirm if GPG Keys are installed...
GPG Keys rpm are installed $
If I run this from the CLI
Code:
rpm -q gpg-pubkey
gpg-pubkey-fd431d51-4ae0493b
gpg-pubkey-2fa658e0-45700c69