The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 04:59 AM
problem with tr command ravi raj kumar UNIX for Advanced & Expert Users 2 07-02-2007 06:41 AM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 10:10 AM
ls command problem buckhtr77 SUN Solaris 2 12-06-2005 04:16 PM
Problem while using Sed command gopskrish UNIX for Dummies Questions & Answers 2 06-27-2005 11:26 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-27-2005
vasikaran vasikaran is offline
Registered User
  
 

Join Date: Jun 2005
Location: india
Posts: 55
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
  #2 (permalink)  
Old 06-27-2005
google's Avatar
google google is offline Forum Advisor  
Moderator
  
 

Join Date: Jul 2002
Location: Atlanta
Posts: 740
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 08:05 AM..
  #3 (permalink)  
Old 06-27-2005
rahul123_libra rahul123_libra is offline
Registered User
  
 

Join Date: May 2005
Posts: 46
Do This

yes use spaces between [ and ]

u can also use

if
....
....
...
fi
  #4 (permalink)  
Old 06-27-2005
vasikaran vasikaran is offline
Registered User
  
 

Join Date: Jun 2005
Location: india
Posts: 55
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
  #5 (permalink)  
Old 06-27-2005
rahul123_libra rahul123_libra is offline
Registered User
  
 

Join Date: May 2005
Posts: 46
Can u plz paste the code of the if block
  #6 (permalink)  
Old 06-27-2005
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,190
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
  #7 (permalink)  
Old 06-28-2005
vasikaran vasikaran is offline
Registered User
  
 

Join Date: Jun 2005
Location: india
Posts: 55
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"
Sponsored Links
Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:04 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0