error

Hello
Any idea where is the error ?
*)
echo " Wrong selection. Try again "
continue
;;
esac
done
echo "Done"

Thanks alot

You can't have an "esac" unless you have a "case" first. Nor a "done" without a "do".

it gives an error like this
syntax error at line 43: `end of file' unexpected

the above code saws only the end of the script

ive got the case and do in my code

How to guess your whole script?

Pls. post your script to here.

echo " a.read a file"
echo " b.create a file"
echo " c.add on existing file"
echo " d. exit"
"; do
echo "Enter a,b,c or d: \c"
read answer
echo
case "$answer" in
a)

read answer
cat $answer
;;
b)

read answer
echo
cat> $answer
;;
c)

read answer
echo
cat>> $answer
;;
d)
break
;;
*)

continue
;;
esac
done
echo "Done"

What is the meaning of in line 5

"; do

??

You may use 'select' to do the same thing more convenience.

PS3="Enter your choice > "
select answer in "read a file" "create a file" "add on existing file" exit;
do
case "$answer" in
1)

read answer
cat $answer
;;
2)

read answer
echo
cat> $answer
;;
3)

read answer
echo
cat>> $answer
;;
4)
exit
;;
*)

print 'Invalid input'
;;
esac
done

I suppose this is what you were intending to do

Regards
JK

echo " a.read a file"
echo " b.create a file"
echo " c.add on existing file"
echo " d. exit"

while [ true ]
do
echo "Enter a,b,c or d: \c"
read answer
echo
case "$answer" in
a)
cat $answer
;;
b)
cat> $answer
;;
c)
cat>> $answer
;;
d)
exit
break
;;
*)
echo "option should be a, b or c"
;;
esac
done

Hi jayakhanna,

Do you know the first variable 'answer' not equal to the second 'answer' in 'case'? Try to think your script problem,

echo " a.read a file"
.
.
while [ true ]
do
echo "Enter a,b,c or d: \c"
read answer
echo
case "$answer" in
a)
cat $answer
;;

if I want to read a file, I press a. According to your 'case', it gives me 'cat a'. I know that you was confused with props' post.

Yeah I was very well aware that both of the variable are same, I assumed that he actually wanted a file name which is equivalent to the answer variable

Thanks and Regards
JK

It's true the OP does, but the $answer variable is used twice - once to store the option a,b,c or d and then to store the name of a file.

props, for the sanity of anyone looking at your program in the future (esp if the program is larger) you may want to use different variable names! :wink:

...
...
echo "Enter a,b,c or d: \c"
read option
case "$option" in
a)
read fileName
cat $fileName
;;
...
...

Thanks for your help . I really appreciate your replies:)