Re: Script Error [syntax error at line]


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Re: Script Error [syntax error at line]
# 1  
Old 08-15-2011
Re: Script Error [syntax error at line]

Hi ,

I Have Written A Simple Script To Check Greatest Of '2' Number When Execuating The Script I Am Getting The Below Error

SP11[4]: if[ 12 -gt 13]:not found [No such file or directory]
SP11: line 4:syntax error at line 5:'then' unexpexted

And The Program I Have Wrriten For This
Code:
#!bin/ksh
echo "Enter Two Numbers"
read a b
if [$a -gt $b]
then
   echo "$a Is Greater"
else
   echo"$b Is Greater"
fi

Thanks

Last edited by vbe; 08-15-2011 at 09:02 AM..
# 2  
Old 08-15-2011
[ is a synonim of the "test" command. Every command should be separated by spaces or ";". So
Code:
if [ $a -gt $b ]

This User Gave Thanks to yazu For This Post:
# 3  
Old 08-15-2011
As yazu corrected... but you had other typos, so:
Code:
#!/usr/bin/ksh
echo "Enter Two Numbers"
read a b
if [ $a -gt $b ]
then
   echo "$a Is Greater"
else
   echo "$b Is Greater"
fi

the executions gives:
Code:
ant:/home/vbe $ ./00001 
Enter Two Numbers
5 9
9 Is Greater

# 4  
Old 08-15-2011
May I suggest using the arithmetic test operator that is built into the shell:
Code:
#!/usr/bin/ksh 
echo "Enter Two Numbers" 
read a b 
if (( $a > $b )); then
  echo "$a Is Greater" 
else 
  echo "$b Is Greater" 
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

2. Shell Programming and Scripting

Error"syntax error at line 15: `end of file' unexpected"

While i m running below code, it is giving me the error"syntax error at line 15: `end of file' unexpected". Pls let me know what is wrong here..i tried many ways, but no luck dbSID="SWQE" usrname="apps" password="Wrgthrk3" count=0 while do sqlplus $usrname/$password@$dbSID... (5 Replies)
Discussion started by: millan
5 Replies

3. Shell Programming and Scripting

Cannot execute/finish script because of last line syntax error: unexpected end of file/token `done'

first of all I thought the argument DONE is necessary for all scripts that have or begin with do statements which I have on my script, However, I still don't completely understand why I am receiving an error I tried adding another done argument statement but didn't do any good. I appreciate... (3 Replies)
Discussion started by: wolf@=NK
3 Replies

4. Shell Programming and Scripting

Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected.

Hi All I am quite new to Unix. Following is a shell script that i have written and getting the subject mentioned error. #!/bin/ksh #------------------------------------------------------------------------- # File: ang_stdnld.ksh # # Desc: UNIX shell script to extract Store information.... (3 Replies)
Discussion started by: amitsinha
3 Replies

5. Shell Programming and Scripting

ERROR: ./launch_full_backup.sh[18]: Syntax error at line 28 : `else' is not expected.

Help please! :confused: I have the following error with the following file and the emails are not arriving to the email, any idea please? ERROR: ./launch_full_backup.sh: Syntax error at line 28 : `else' is not expected. FECHA=`date +%d%m%y%H%M`... (2 Replies)
Discussion started by: villenan
2 Replies

6. Shell Programming and Scripting

Urgent: Script.sh: syntax error at line 72: `PROGRESS=$' unexpected

I have written a shell script to Automatically FTP a file. The script runs fine when doing it manually but when I schedule it using a crontab it gives me an error. . . . echo "-----------------Starting File FTP---------------------" >> $PROS_LOAD_LOG echo "open X.XX.XX.XXX" >>... (13 Replies)
Discussion started by: tanhajoy
13 Replies

7. Shell Programming and Scripting

Help on shell script : syntax error at line 62: `end of file' unexpected

Hi All, I have written a korn script (code pasted below). It is giving the error while debugging "new.sh: syntax error at line 62: `end of file' unexpected". I have re-written the whole code in VI and explored all help related to this error on this Unix forum and tried it. Somehow, I could... (7 Replies)
Discussion started by: schandrakar1
7 Replies

8. UNIX for Dummies Questions & Answers

awk Shell Script error : "Syntax Error : `Split' unexpected

hi there i write one awk script file in shell programing the code is related to dd/mm/yy to month, day year format but i get an error please can anybody help me out in this problem ?????? i give my code here including error awk ` # date-month -- convert mm/dd/yy to month day,... (2 Replies)
Discussion started by: Herry
2 Replies

9. Shell Programming and Scripting

syntax error, need to redo one line in script :(

I have a script that processes a file with two columns (IDs and Idle session times): # cat /tmp/idle-ids.lst user1 2,390 user2 97 user3 93 user4 67 user5 56 user6 33 user7 22 user8 6 user9 2 user10 0 my script works, but has... (4 Replies)
Discussion started by: mr_manny
4 Replies

10. UNIX for Advanced & Expert Users

I got error like...syntax error on line 1, teletype

Hi All, when i executing scripts i got error like: syntax error on line 1, teletype expr: syntax error expr: syntax error expr: syntax error Please advise to me. Note: Yesterday it's working fine, 2day only i got error. (2 Replies)
Discussion started by: koti_rama
2 Replies
Login or Register to Ask a Question