troubleshooting Question

compare variables in UNIX shell

Avatar of pavelmed
pavelmed asked on
Shell Scripting
5 Comments1 Solution424 ViewsLast Modified:
I am trying to compare two variables in shell script, but it does not work although the code looks simple.
Basically the idea is to determine when an empty string is entered by a user and display a warning.
This is the code:
#!/bin/sh
echo "Enter value A:"
read  VALUEA
echo "$VALUEA"

echo "Enter VALUE B:"
read VALUEB
echo "$VALUEB"

X="5"
echo "$X"

if [ "$X$VALUEA"="$X" ];  then
 echo "You did not enter Value A.  Please try again $X$VALUEA and $X"
else
 echo "not empty"
fi

if [ "$X$VALUEB"="$X" ];  then
 echo "You did not enter ending date.  Please try again $X$VALUEB  and $X"
 else
 echo "not empty"
fi

exit
---------------------------
The problem is that regardless whether or not I enter a value A or B, it always displays:
You did not enter beginning date.  Please try again 5r and 5
You did not enter ending date.  Please try again 5  and 5

("r" is a value I entered for the value A.  I used that as a debugging display).

Please assist.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros