Reputation: 1212
I have searched and tried numerous solutions but being new to shell I am lost. I am setting a variable in one .sh, calling a second, then trying to act on whether it is true or not.
testA.sh
#!/bin/sh
DB=1
. testB.sh
------------------------------------
testB.sh
if ${DB}==1; then
echo "DB is on"
fi
I get 1==1 command not found.
Upvotes: 1
Views: 92
Reputation: 212298
if you want to test whether or not a variable is set, the standard way is:
if test "${DB+set}" = set; then # here, $DB is set fi
If you want to check that it is set to a particular string value, use:
if test "$DB" = value; ...
if you want to check for a particular integer value:
if test "$DB" -eq 4; ...
The last form will generate an error message if DB is a string value that does not look like an integer.
Upvotes: 1
Reputation: 29625
should be:
if [[ "$DB" = "1"]]; then
or
if [[ $DB -eq 1 ]]; then
Upvotes: 5