0

I'm having real trouble getting my script to work, it's about 3 pages long and I'm having trouble with one of my if...then constructs. The code for the sub is as follows:

check_a_b () {
	CHECKA="634274"
	CHECKB="512274"
	if [ CHECKA=CHECKB ]; then
		echo "Match"	
		echo "$CHECKA" >> "$LOGFILE"	
		echo "$CHECKB" >> "$LOGFILE"	
	else
		echo "No match"
		echo "$CHECKA" >> "$LOGFILE"	
		echo "$CHECKB" >> "$LOGFILE"	
	fi
}

I'm running this script under MacOS X Darwin. The script above, when executed, prints "Match" ... although I'm fairly certain that CHECKA and CHECKB are different. If I remove the last space in the IF brackets, ie:

if [ CHECKA=CHECKB ]; then

becomes:

if [ CHECKA=CHECKB]; then

Then it prints "No match", and cannot be coaxed into printing "Match", even when I use:

if [ CHECKA=CHECKA]; then

I'm really confused! :cry:
Thanks in advance ...

4
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by eggi
0

inside the if, you should be comparing $CHECKA and $CHECKB, not CHECKA and CHECKBKeep the space there. Also, try removing the ; and move 'then' to the next line. (not sure if this matters)

0

I would agree to a little bit of both

if [ "$CHECKA" == "CHECKB" ]; then

I'm not sure if the Mac OS underlying *nix requires you to use the $ prefix to expand your variables values.

Best of luck :)

, Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.