This is Vasikaran, I am just trying to run the if command using this test program, but while running , i am getting the syntax error as
"syntax error: unexpected end of file"
this is the test program
******************
echo " enter number"
read num
echo "Enter the choice of you want to see "
echo "1. 1message"
echo "2. 2message"
echo "3. 3message"
read choice
if (choice=1) then
echo "This is reading the first choice"
endif
Pls note : i am running this program in linux environment
Change the "if" line to this: Note there the spaces after the "[" and before the "]" are required. Also, to access the value of a variable in shell, prefix the variable with a "$" sign. Use "fi" to close the "if" statement.
if [ $choice -eq 1 ] then
echo "This is reading the first choice"
fi
You can clean up your code by using a "select case" which will build the menu for you. Here is the syntax (note that the ";;" must end every case.)
select NUM in 1 2 3 quit
do
case $NUM in
1) echo "This is reading the first choice"
;;
2) echo "This is reading the second choice"
;;
3) echo "This is reading the third choice"
;;
quit) echo "Goodbye"
exit;;
esac
done
Lastly, to fancy it up a bit, use the builtin variable PS3 to set your prompt string for the menu (Add it just before the "select case" statement)
Neither of the suggestions will work for the OP as he is using a csh base shell. I'm pretty rusty on csh but I think it should be something like
echo " enter number"
read num
echo "Enter the choice of you want to see "
echo "1. 1message"
echo "2. 2message"
echo "3. 3message"
read choice
if ( $choice == 1 ) then
echo "This is reading the first choice"
endif
Actually i am trying the following code when in run this program in linux environment
echo " enter the mobile number "
read mob
echo "Enter the choice of log you want to see "
echo "1. F.log"
echo "2. A.log"
echo "3. I.log"
echo "4. R.log"
echo "5. M.log"
echo "6. A.log"
read choice
if [ $choice == 1 ] then
echo "This will give the contents present in f.log"
grep $mob /data/logs/f.log | cut -f1,2,4,5,11 -d" "
endif