I want to use if conition for my script. Before I used it tried it with some small test scripts. But it was not succeeded. My script and screen output as follows,
Script:
echo 'Do you think Yes or No (y/n) : '
read ans
echo You input anser as $ans
ans1=y
if ( $ans == $ans1 )
then
echo good!
else
echo bad!
fi
screen output
Do you think Yes or No (y/n) :
y
You input anser as y
y: not found
bad!
Do you think Yes or No (y/n) :
n
You input anser as n
n: not found
bad!
Can somebody please pleasse tell me what is the error ?
I tried this several times with different formats in tcshell.
Why dont you try it in a different shell say bash.
Look at this
sh-2.05b$ cat mahesh.sh
#! /bin/sh
echo 'Do you think Yes or No (y/n) : '
read ans
echo You input anser as $ans
ans1=y
if [ $ans == $ans1 ] ; then
echo good!
else
echo bad!
fi ;
sh-2.05b$ ./mahesh.sh
Do you think Yes or No (y/n) :
y
You input anser as y
good!
sh-2.05b$ ./mahesh.sh
Do you think Yes or No (y/n) :
n
You input anser as n
bad!