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.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.