]echo "Do you want to say yes or no ?(y/n)[n]:\c"
read ans
here 'n' is the default value.that means if the user press ENTER key then it should be 'n' .
Now how do i know that the user has pressed ENTER key.What will be stored in my variable 'ans'.
ans will contain what you typed until the enter key was pressed. If you only press enter, then that variable will be empty.
To do what you want, you need to do something like:
echo "Do you want to say yes or no ?(y/n)[n]:\c"
read ans
case $ans in
n|"")
echo no;;
y)
echo yes;;
*)
echo other;;
esac
I've modified the code I posted before, have a look at it now. It works in Linux (bash) also.
What I meant with empty was "no printable chars", I'm sorry