if command -problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers if command -problem
# 1  
Old 06-27-2005
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  
Old 06-27-2005
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 09:05 AM..
# 3  
Old 06-27-2005
Do This

yes use spaces between [ and ]

u can also use

if
....
....
...
fi
# 4  
Old 06-27-2005
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  
Old 06-27-2005
Can u plz paste the code of the if block
# 6  
Old 06-27-2005
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  
Old 06-28-2005
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"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

I'm facing problem with rpm command, when running the command and appears this error:

exec(): 0509-036 Cannot load program /usr/opt/freeware/bin/rpm because of the following errors: 0509-022 Cannot load module /opt/freeware/lib/libintl.a(libintl.so.1). 0509-150 Dependent module /opt/freeware/lib/libiconv.a(shr4.o) could not be loaded. 0509-152 Member... (4 Replies)
Discussion started by: Ohmkar
4 Replies

2. Shell Programming and Scripting

Problem with tr command

Hi friends, Today I found one strange behaviour of the tr command. I used the following command: echo "NEE"|tr Sometimes it was giving "nee" as ouput . sometimes it was giving "NEE" as output. Finally I used the below code: echo "NEE"|tr "" "" ... and it gave me the correct... (17 Replies)
Discussion started by: neelmani
17 Replies

3. Shell Programming and Scripting

Problem with mv command and touch command

Hi guys, first of all I would say that this is my first time I write in a Forum. I've read the "forum rules" and I hope i will respect them. I searched everywhere for the solution of my problem but I didn't find anything. Here my problem: I'm using a sap job scheduler: in a particular job... (7 Replies)
Discussion started by: Antcam
7 Replies

4. Red Hat

please help me in if command problem

Please help me this script !!!! Script ***** a=2.0.0.0 b=1.0.0.0 #if test $a -ge $b if then echo "A is Greater than B" else echo "B is Greater than A" fi i am getting following error >sh abc abc: line 6: [: 2.0.0.0: integer expression expected (8 Replies)
Discussion started by: ponmuthu
8 Replies

5. Shell Programming and Scripting

Problem with command tr

Hello, excuse me for my english, i'm a french man. I have a problem with the command tr in applescript (with the accent...in french we have a lot of accents), i have read that is a problem with the version 10.5 of leopard then i would want to download the version 10.4 of universal binary of tr... (1 Reply)
Discussion started by: protocomm
1 Replies

6. Solaris

problem with ps command

Hi all I use to run sql loader inside a script with usename and password written in syntax. Now when I use 'ps' command to know about the status of loading, it also shows username and password that I don't want to share with someone who is sitting with me. If you have any idea except encryption... (1 Reply)
Discussion started by: sanjay1979
1 Replies

7. UNIX for Dummies Questions & Answers

problem with output of find command being input to basename command...

Hi, I am triying to make sure that there exists only one file with the pattern abc* in path /path/. This directory is having many huge files. If there is only one file then I have to take its complete name only to use furter in my script. I am planning to do like this: if ; then... (2 Replies)
Discussion started by: new_learner
2 Replies

8. Shell Programming and Scripting

problem with dd command or maybe AFS problem

Hi, folks. Sorry for bothering, but maybe someone could help me please. The problem is the following: there is some script that copies files from local file system to AFS. The copying is performed with dd command. The script copies data into some AFS volumes. The problem appeared with one... (0 Replies)
Discussion started by: Anta
0 Replies

9. UNIX for Dummies Questions & Answers

Problem with ps command??

I have a problem to.... (1).List the number of unique users that has active processes. (2).List the number of active processes for each of the users in (1). (3).Determine total memory usage for each user. Help me please....thank you. Best... (2 Replies)
Discussion started by: robocup
2 Replies

10. UNIX for Dummies Questions & Answers

problem with who command

Sorry for my poor english. Unix is SCO ODT ver 3.0 Mine problem is : when I login via some terminal emulator and type : who am i I see information like this : username ttyp02 Feb 28 09:53 after logoff and type who command (from some other terminal) I see that ttyp02 is still... (2 Replies)
Discussion started by: bane_yu
2 Replies
Login or Register to Ask a Question