When I tried to run receive.sh,it returned following errors.
syntax error near unexpected token `do
#!/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}
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
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
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?
#!/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
The issue is resloved,I edited the code in Windows and uploaded it to a Unix machine,so the error occured,I format it to Unix format with UltraEditor and modified sentences such like
then all the sh files ran well in Unix server.
I don't know which release the Kore shell is,typed $ print $(.sh.version) and $ what /bin/ksh entirely returned "Command not found",but anyway,appreciate your kind aid.
With ksh, -x is a valid option for set .
Try to create and execute the following small script. It must run without problem.
#!/usr/bin/ksh
set -x
echo $SHELL
If you get an error, the problem comes from your shell, otherwise rewrite the lines 1 and 2 of your script (and correct the little error, see below) and retry.
#!/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