The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem in awk command viveksnv Shell Programming and Scripting 3 03-03-2008 12:59 AM
problem with tr command ravi raj kumar UNIX for Advanced & Expert Users 2 07-02-2007 03:41 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
ls command problem buckhtr77 SUN Solaris 2 12-06-2005 12:16 PM
Problem while using Sed command gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 08:26 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Location: india
Posts: 55
Stumble this Post!
if command -problem

Hi,

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

Thanks for the help in advance.

Vasikaran
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-27-2005
google's Avatar
Moderator
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
Stumble this Post!
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.

Code:
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.)
Code:
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)
Code:
PS3="Make a Selection From the Following List"

Last edited by google; 06-27-2005 at 05:05 AM.
Reply With Quote
  #3 (permalink)  
Old 06-27-2005
Registered User
 

Join Date: May 2005
Posts: 46
Stumble this Post!
Do This

yes use spaces between [ and ]

u can also use

if
....
....
...
fi
Reply With Quote
  #4 (permalink)  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Location: india
Posts: 55
Stumble this Post!
Still problem persists

Thanks for the reply..

I have tried using if .........fi command but while trying i am getting this below mentioned error.. pls help

Ofcourse case statement is working, but i want to work it out with If statement..

"syntax error near unexpected token `fi'
search1.sh: line 16: `fi'"

Thanks and Regards
Vasikaran
Reply With Quote
  #5 (permalink)  
Old 06-27-2005
Registered User
 

Join Date: May 2005
Posts: 46
Stumble this Post!
Can u plz paste the code of the if block
Reply With Quote
  #6 (permalink)  
Old 06-27-2005
reborg's Avatar
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,513
Stumble this Post!
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

Code:
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
Reply With Quote
  #7 (permalink)  
Old 06-27-2005
Registered User
 

Join Date: Jun 2005
Location: india
Posts: 55
Stumble this Post!
sending you the code and error message, still, error persists.. pls help

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


the error message i am getting as

"line 17: syntax error: unexpected end of file"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0