I'm new to bash scripting and how it works. My following problem: Since the value returned from my function get_value is stored in a variable either (value1 or value2) my error message is not printed out to the user.
I only want the script to continue running if both value1 and value2 receives a valid value from the get_value function, but I would also like to notify the user which of them are missing and needs to be created.
I've simplified my two functions:
get_value()
{
VALUE=$(*RUNNING COMMAND* 2> /dev/null)
if [ -z $VALUE ]; then
echo "ERROR Could not find value"
exit 1
else
echo $VALUE // Returning the value
fi
}
print_value()
{
VAR1="not_exists"
VAR2="exists"
value1=$(get_value "$VAR1")
value2=$(get_value "$VAR2")
echo "$value1 and $value2"
}
Current output: (blank).
I know the value from the if-statement is saved in the variable that is calling the function, however I do not want the Error-message and the exit to be stored into the variable but rather printed out to the screen to notify the user.