Need help on this simple script... I am scratching my head...

when I do
echo $myhost
it returns db3

However, when running the script, the first IF condition is always true... what went wrong? Thanks!

Here is the script:

myhost=`hostname -s`

if [ $myhost='db1' ]; then
echo "###############################################"
echo "### Welcome to Site 1 ###"
echo "###############################################"

if [ -f /db2home/db2idev1/sqllib/db2profile ]; then
. /db2home/db2idev1/sqllib/db2profile
fi

elif [ $myhost='db2' ]; then
echo "###############################################"
echo "### Welcome to Site 2 ###"
echo "###############################################"

if [ -f /db2home/db2iuat1/sqllib/db2profile ]; then
. /db2home/db2iuat1/sqllib/db2profile
fi

elif [ $myhost='db3' ]; then
echo "####################################################"
echo "### Welcome to Site 3 ###"
echo "####################################################"

if [ -f /db2home/db2iprd1/sqllib/db2profile ]; then
. /db2home/db2iprd1/sqllib/db2profile
fi

else

echo "exit"
exit 1
fi

i got it, take the ' ' out of the if condition....
for example
if [ $myhost = db1 ]; then
this works!

One thing I noticed, too, was that you are using = instead of == . = can assign values to a variable, whereas == checks for equality.

That might have something to do with it, too...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.