The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 11:16 AM
syntax error at line 59: `end of file' unexpected Remi SUN Solaris 4 01-16-2007 02:48 PM
sh: syntax error: `...' unexpected??? alan Shell Programming and Scripting 5 06-22-2004 07:58 PM
sh: syntax error at line 1: `>' unexpected atiato High Level Programming 2 03-16-2004 07:39 AM
syntax error: `(' unexpected adadevil UNIX for Dummies Questions & Answers 11 12-14-2001 09:17 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2007
joshuaduan joshuaduan is offline
Registered User
  
 

Join Date: May 2007
Posts: 11
Question syntax error near unexpected token...what caused?

Dear all,

When I tried to run receive.sh,it returned following errors.
syntax error near unexpected token `do

Code:
#!/usr/bin/ksh
GlobalValueReceive=r
GlobalValueWorking=w
GlobalValueTemp=t

$exec 0<Property
while read LineInProperty
do
  if [ ${LineInProperty:0:11} = New_receive ]
  then
     $GlobalValueReceive = ${LineInProperty:25} 
  fi
  if [ ${LineInProperty:0:11} = New_working ]
  then
     $GlobalValueWorking = ${LineInProperty:25}
  fi
  if [ ${LineInProperty:0:8} = New_temp ]
  then
     $GlobalValueTemp = ${LineInProperty:22}
  fi
done

(($#<2)) && { print "2 parameters: \n    p_seq_no\n    p_sys_ind"; exit 1; }

typeset -i pass_check
typeset -i p_seq_id

p_seq_id=$1
p_sys_ind=$2
pass_check=0

# file's count
check_count=`ls -l ${GlobalValueReceive}/${p_sys_ind}.Witness*|grep "^-"|wc -l`

print ${check_count} seq files

for i in $(ls ${GlobalValueReceive}/${p_sys_ind}.Witness*)
do
  seq_id=${i##*Witness.}
  seq_id=${seq_id%%.*}
  mv ${GlobalValueReceive}/${p_sys_ind}.*.${seq_id}.* ${GlobalValueTemp}/dos/
done

for i in $(ls ${GlobalValueTemp}/dos/*)
do
  #dos2ux ${i} > ${GlobalValueTemp}/dos2/${i##${GlobalValueTemp}/dos/}
cat ${i} > ${GlobalValueTemp}/dos2/${i##${GlobalValueTemp}/dos/}
cat ${GlobalValueTemp}/dos2/${i##${GlobalValueTemp}/dos/} | tr -d "
" > ${GlobalValueTemp}/${i##${GlobalValueTemp}/dos/}   
  rm ${i}
done

print files have been moved to temp folder

for i in $(ls ${GlobalValueTemp}/${p_sys_ind}.Witness*)
do
  print begin to check the files with seq_id ${p_seq_id}
  if [ ${p_sys_ind} = 111111 ]
  then
    /home/bodi/bin/ef_validate.sh ${p_seq_id}
  else
    /home/bodi/bin/mp_validate.sh ${p_seq_id}  
  fi
  
  return_code=$?
  if [ ${return_code} = 0 ]
  then
    print file with seq_id ${p_seq_id} passed!
    mv ${GlobalValueTemp}/${p_sys_ind}.*.${p_seq_id}.* $GlobalValueWorking/
    mv $GlobalValueWorking/${p_sys_ind}.Witness.${p_seq_id}.*.txt $GlobalValueWorking/${p_sys_ind}.Witness.${p_seq_id}.txt 
    pass_check=${pass_check}+1
    p_seq_id=${p_seq_id}+1
  else
    print file with seq_id ${p_seq_id} failed!
    for j in $(ls ${GlobalValueTemp}/${p_sys_ind}.*.${p_seq_id}.*)
    do
      mv ${j} ${GlobalValueWorking}/${return_code}.${j##${GlobalValueTemp}/}.rej
    done
    for j in $(ls ${GlobalValueTemp}/${p_sys_ind}.*)
    do
      mv ${j} ${GlobalValueWorking}/1.${j##${GlobalValueTemp}/}.rej
    done
    break
  fi
done

print quit with ${pass_check} passed check  
exit ${pass_check}

Appreciate to any helper.
Thanks.
  #2 (permalink)  
Old 05-11-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,428
Code:
exec 0<Property  # $exec replaced by exec
while read LineInProperty
do
  if [ ${LineInProperty:0:11} = New_receive ]
  then
     GlobalValueReceive=${LineInProperty:25} # $ removed + No spaces around =
  fi
  if [ ${LineInProperty:0:11} = New_working ]
  then
     GlobalValueWorking=${LineInProperty:25}
  fi
  if [ ${LineInProperty:0:8} = New_temp ]
  then
     GlobalValueTemp=${LineInProperty:22}
  fi
done
Execute your script with the trace option -x

Jean-Pierre.
  #3 (permalink)  
Old 05-11-2007
joshuaduan joshuaduan is offline
Registered User
  
 

Join Date: May 2007
Posts: 11
Quote:
Originally Posted by aigles
Code:
exec 0<Property  # $exec replaced by exec
while read LineInProperty
do
  if [ ${LineInProperty:0:11} = New_receive ]
  then
     GlobalValueReceive=${LineInProperty:25} # $ removed + No spaces around =
  fi
  if [ ${LineInProperty:0:11} = New_working ]
  then
     GlobalValueWorking=${LineInProperty:25}
  fi
  if [ ${LineInProperty:0:8} = New_temp ]
  then
     GlobalValueTemp=${LineInProperty:22}
  fi
done
Execute your script with the trace option -x

Jean-Pierre.
Hello,Mr.Jean-Pierre

Sorry for any misreading ,did you mean that I should modify the code like following?

Quote:
$exec 0<Property
while read LineInProperty
do
if [ ${LineInProperty:0:11} = New_receive ]
then
GlobalValueReceive = {LineInProperty:25}
fi
if [ {LineInProperty:0:11} = New_working ]
then
GlobalValueWorking = {LineInProperty:25}
fi
if [ ${LineInProperty:0:8} = New_temp ]
then
GlobalValueTemp = {LineInProperty:22}
fi
done
I executed the sh file with sh filename.sh,is this correct?

Dear Mr.Jean,I just touched the Korn shell script several days,thank you so much for your assistance.

Regards,
Joshua.Duan
  #4 (permalink)  
Old 05-11-2007
LiquidChild LiquidChild is offline
Registered User
  
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
No he meant:


set -x

exec 0<Property
while read LineInProperty
do
if [ ${LineInProperty:0:11} = New_receive ]
then
GlobalValueReceive={LineInProperty:25}
fi
if [ {LineInProperty:0:11} = New_working ]
then
GlobalValueWorking={LineInProperty:25}
fi
if [ ${LineInProperty:0:8} = New_temp ]
then
GlobalValueTemp={LineInProperty:22}
fi
done
  #5 (permalink)  
Old 05-13-2007
joshuaduan joshuaduan is offline
Registered User
  
 

Join Date: May 2007
Posts: 11
Still had problem

Hi,I've corrected the code as above.The file ran normally,but it had a error prompt: :invalid option line 2 : set: -2 (the snap shot is in the attachment.)

I can't remove set -x,or the code won't run.What shall I do?

Code:
#!/usr/bin/ksh
set -x

GlobalValueWorking=w


exec 0<Property

while read LineInProperty
do
  if [ ${LineInProperty:0:11} = New_working ]
  then
     GlobalValueWorking={LineInProperty:25}
  fi
done
Attached Images
File Type: bmp invalidOption.bmp (27.4 KB, 85 views)
  #6 (permalink)  
Old 05-14-2007
LiquidChild LiquidChild is offline
Registered User
  
 

Join Date: Jul 2005
Location: Belfast
Posts: 49
I don't get why the set -x option would stop this running if removed, what happens when you do?
Closed Thread

Bookmarks

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 02:21 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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