Hi,
I am trying to read the value passed by the user and store it in a variable so that later I can read it from the variable. But I am getting errors. Can you please help? Thanks.
Code:
$ECHO "Enter the Country for which you want the installation to be executed? (US/India):"
read COUNTRY
if [ "$COUNTRY" = "us" -o "$COUNTRY" = "US" ]
then
$COUNTRY="US"
else
$COUNTRY="India"
fi
$echo "The installation is for: $COUNTRY"
Execution Result:
./Country_Test.sh: line 4: Enter the Country for which you want the installation to be executed?: command not found
us
./Country_Test.sh: line 8: us=US: command not found
./Country_Test.sh: line 13: The installation is for: us: command not found
echo "Enter the Country for which you want the installation to be executed? (US/India):"
read COUNTRY
if [ "$COUNTRY" = "us" -o "$COUNTRY" = "US" ]
then
COUNTRY="US"
else
COUNTRY="India"
fi
echo "The installation is for: $COUNTRY"
To be independent from the case of the characters that have been input, you can use this:
cat mach.ksh:
echo "Enter the Country for which you want the installation to be executed? (US/India):"
read COUNTRY
COUNTRY=`echo ${COUNTRY} | tr -s '[A-Z]' '[a-z]'`
case ${COUNTRY} in
us) COUNTRY="US";;
india) COUNTRY="India";;
esac
echo Country: ${COUNTRY}
Example:
./mach.ksh
Enter the Country for which you want the installation to be executed? (US/India):
uS
Country: US
./mach.ksh
Enter the Country for which you want the installation to be executed? (US/India):
iNdIA
Country: India