Consider the following function:
function testForBinary {
someBin=$(command -v binary)
# Test if binary is installed
if [[ -n $someBin ]]; then
installSuccess="Success"
echo ${installSuccess}
return
else
# This should never be reached
return 1
fi
}
taken from (Context):
function installAndTestForDialog() {
# dialog allows me to create a pretty installer
# It is a required dependency since XXXXX
# Name Removed as I'm attempting modularization
# of a script from Github that's one huge Script
# See https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then
local dialogBin
local updated=false
local dialogInstallSuccess
dialogBin=$(command -v dialog)
if [[ -z $dialogBin ]]; then
printf "Installing dialog... "
if [[ $updated -eq 0 ]]; then
apt-get update > /dev/null 2>&1
updated=true
fi
# Debian Based OS
apt-get -y install dialog > /dev/null 2>&1
# Test if dialog is installed to verify installation
# above was successful.
dialogBin=$(command -v dialog)
if [[ -n $dialogBin ]]; then
# I cannot get this to echo success
# if I echo from here
dialogInstallSuccess="Success"
# Moving it here doesn't help either Why??
echo ${dialogInstallSuccess}
return
else
# This should never be reached
return 1
fi
fi
}
I'm attempting to treat installSuccess as a boolean, but what am I doing wrong. If I write the function as above, and then add:
isInstalled=$(testForBinary)
echo "$isInstalled"
isInstalled returns a blank line. I know this isn't true because when I run command -v binary outside the function, the path to binary results.
Output (Context):
Function and Variable Output Test
=====================
# These are other tests
# I'm performing, but note
# the blank line, which should
# print Success
2.9-MODULAR
192.168.1.227
false
false
(blank line)