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:
echo "Enter value A:"
read  VALUEA
echo "$VALUEA"

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

echo "$X"

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

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

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 our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
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