My goal is to create a script that will check if in a test or production environment. I wrote this script to check $host variable to check which server I'm on but this script does not work.
if [ "$host" == "abc_test" ]
then
BASE=/home/fmtest; export BASE
else
BASE=/home/fmprod; export BASE
fi
echo $BASE
No matter which server I run this on (Test or Production) it echo's "/home/fmtest"
An if this is actually "ksh", the "==" is invalid: Anyway we always put quotes round a string comparison.
if [ "$(hostname)" = "abc_test" ]
then
BASE=/home/fmtest; export BASE
else
BASE=/home/fmprod; export BASE
fi
echo $BASE
Worth checking what the output from the hostname command looks like because it should be the full qualified hostname and may be different from uname -n .
@fpmurphy
Agreed. It's also not necessary in ksh88. If you omit the quotes you do get a syntax error if any of the variables are empty.
However I'm on a one-man mission to try to get the populus to put quotes round strings because this second only to misuse of "for" in the common scripting errors posted on this board.