elif if not expected


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting elif if not expected
# 8  
Old 12-30-2011
Code:
 
SRCFILE_DATA_CHECK()
{
echo 'Sourcefile_Record count is:'$COUNT_SRC
if [[ $COUNT_SRC -le 0 ]]; then
echo 'Record count is zero in Sourcefile Exiting'
exit 0
else
echo "Source file is not empty"
fi
}
ARCHIVE_TGT()
{
mv ${filetgt} ${filetgt_bkp} 
if [[ $? != 0 ]]; then
echo "Archiving of Target File failed. Exiting"
exit -1
fi
}
ARCHIVE_SRC()
{
cp ${filesrc} ${filesrc_bkp}

if [[ $? != 0 ]]; then
echo "Archiving of Source File failed. Exiting"
exit -1
fi
}
RENAME_SRC()
{
mv ${filesrc} ${filetgt}

if [[ $? != 0 ]]; then
echo "Renaming of Source File failed. Exiting"
exit -1
fi
}
CHK_COUNT()
{
if [[ ${COUNT_SRC} == ${COUNT_DELTA_SRC} ]]; then 
echo "Count's are matching between Source & RecordCount File"
else
echo "Count match between Source & RecordCount File Failed. Exiting"
exit -1
fi
}
ACCUMULATE_SRC()
{
echo "Period is same in Source and Target file. Concatenating Source and Target file"
cat ${filesrc} >> ${filetgt}
if [[ $? != 0 ]]; then
echo "Concatenation failed. Exiting"
exit -1
fi
}
 
if [ "${PROCESS_DELTA_CHECK}" -eq "F" ] ; then

ARCHIVE_TGT()

ARCHIVE_SRC()

RENAME_SRC()

CHK_COUNT()

 
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then

ACCUMULATE_SRC()

Timestamp to the target file
ARCHIVE_SRC()

CHK_COUNT()

 
else
 
ARCHIVE_TGT()

ARCHIVE_SRC()

RENAME_SRC()

CHK_COUNT()
fi

---------- Post updated at 04:24 PM ---------- Previous update was at 04:22 PM ----------

-x output is:
Code:
+ + echo /data/datastage/cat/dev/temp1
+ awk -F/ {print $5}
P5=dev
+ srcpath=/data/datastage/cat/dev/flatfiles
+ tgtpath=/data/datastage/cat/dev/flatfiles
+ archpath=/data/datastage/cat/dev/archive
+ srcfilename=WFP_3259_Source.txt
+ srcdeltafilename=WFP_3259_RecordCount.txt
+ tgtfilename=RTR_IDD3295_ECC_Accumulated_Source.txt
+ + date +%Y%m%d%H%M
tgtfilename_new=RTR_IDD3295_ECC_Accumulated_Source_201112300550.txt
+ + date +%Y%m%d%H%M
srcfilename_bkp=WFP_3259_Source_201112300550.txt
+ cd /data/datastage/cat/dev/flatfiles
+ filesrc=/data/datastage/cat/dev/flatfiles/WFP_3259_Source.txt
+ filesrc_bkp=/data/datastage/cat/dev/archive/WFP_3259_Source_201112300550.txt
+ filedelta=/data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ filetgt=/data/datastage/cat/dev/flatfiles/RTR_IDD3295_ECC_Accumulated_Source.txt
+ filetgt_bkp=/data/datastage/cat/dev/archive/RTR_IDD3295_ECC_Accumulated_Source_201112300550.txt
+ + tail -r /data/datastage/cat/dev/flatfiles/RTR_IDD3295_ECC_Accumulated_Source.txt
+ head -1
+ cut -d , -f 4
PERIOD_TGT=009
+ + head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ cut -d , -f 1
COUNT_DELTA_SRC=06
+ + cut -d , -f 2
+ head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
PERIOD_DELTA_SRC=009
+ + head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ cut -d , -f 3
PROCESS_DELTA_CHECK=F
+ + cat /data/datastage/cat/dev/flatfiles/WFP_3259_Source.txt
+ awk {n++} END {print n}
COUNT_SRC=6
+ echo Period on Target File is:009
Period on Target File is:009
+ echo Count of Record Count File is:06
Count of Record Count File is:06
+ echo Period on Record Count File is:009
Period on Record Count File is:009
+ echo File is an Delta (D) or Full (F):F
File is an Delta (D) or Full (F):F
+ echo Count of Source File is:6
Count of Source File is:6
+ set -x
./MainScript.sh[122]: 0403-057 Syntax error at line 136 : `elif' is not expected.


Last edited by methyl; 12-30-2011 at 07:11 AM.. Reason: remove strange font, fix width of some lines
# 9  
Old 12-30-2011
(Crossed post - but still largely current)

Don't forget the correction from post #4.
When creating the function we have the brackets "TEST_SRC()". When invoking the function we do not have the brackets "TEST_SRC".

Quote:
elif [ "$A_TGT" -eq "$A_DLT_SRC" ]; then
Should be:
Code:
elif [ "$A_TGT" = "$A_DLT_SRC" ]; then

Please post the whole script and mention what Operating System and version you have and what Shell you are using.

If at any time this script has been edited in a Microsoft editor, please post the output from this command which is designed to make control characters visible:
Code:
sed -n l scriptname


ADDENDA: After seeing the latest script:
Quote:
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then
Spaces missing around operator and wrong operator and missing { }:
Code:
elif [ "${PERIOD_TGT}" = "${PERIOD_DELTA_SRC}" ] ; then


Quote:
if [ "${PROCESS_DELTA_CHECK}" -eq "F" ] ; then
Wrong operator.
Code:
if [ "${PROCESS_DELTA_CHECK}" = "F" ] ; then


Quote:
exit -1
Convention says exit with a positive number if you fail so you can test $? in any caling script.
Code:
exit 1


Quote:
Timestamp to the target file
Presumably this is a comment line.
Code:
#Timestamp to the target file


Last edited by methyl; 12-30-2011 at 07:17 AM..
# 10  
Old 12-30-2011
Yes its working fine... Thanks a lot all for your help I forget to remove () while calling the functions
# 11  
Old 12-30-2011
I dont know if its a typo or something cause I don't find any space between tokens here... And use "=" if they are numbers...

Code:
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then

Code:
elif [ "${PERIOD_TGT}" -eq "$PERIOD_DELTA_SRC" ] ; then

--ahamed
# 12  
Old 12-30-2011
its typing mistake only.. Script working fine... Thanks all
# 13  
Old 12-30-2011
Code:
if [ "${PROCESS_DELTA_CHECK}" -eq "F" ] ; then
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then
ACCUMULATE_SRC()
#Timestamp to the target file
ARCHIVE_SRC()
CHK_COUNT()
else
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
fi

Code:
This would be easier to follow as:
if [ "${PROCESS_DELTA_CHECK}" = "F" -a "${PERIOD_TGT}" = "${PERIOD_DELTA_SRC}" ]
then
        ACCUMULATE_SRC
        #Timestamp to the target file
        ARCHIVE_SRC
        CHK_COUNT
else
        ARCHIVE_TGT
        ARCHIVE_SRC
        RENAME_SRC
        CHK_COUNT
fi

This User Gave Thanks to methyl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with elif and else

Hello experts, I am having problems with ELIF. Please see the below code : read a; read b; read c; if || || ; then echo "EQUILATERAL" elif || || ; then echo "SCALENE" else echo "ISOSCELES" fi This code works fine for the EQUILATERAL case but fails completely for the... (5 Replies)
Discussion started by: H squared
5 Replies

2. Shell Programming and Scripting

If / elif

Hello all, I have a scenario where I take user input values and accordingly take actions say I run a script with sh scriptname -x GB -e txt (txt can also be text) I have used if clause for the first input (-x GB)and it is working fine Now for second the scenario is if then echo... (3 Replies)
Discussion started by: nnani
3 Replies

3. UNIX for Advanced & Expert Users

if else elif

Hi all,i have configured the following script to check if the file exists or not, #!/bin/sh sleep 30 { FILEFULL=$1`date +$2`* if ; then echo $FILEFULL exist else echo "$FILEFULL File not Found" | mail -s 'server' myaccount@mydomain.com fi } but i have a problem, i need to... (2 Replies)
Discussion started by: charli1
2 Replies

4. Shell Programming and Scripting

While-read and if-elif

Hi there, new to this forum and I recently encounter this problem: I tried to use if-elif loop in a while-read loop, something like this: #!/bin/bash while read myline1 myline2 do if ; then echo "Successful!" elif ; then echo "Failed" fi done < $1 Input file looks like this: 200... (13 Replies)
Discussion started by: kennethtls
13 Replies

5. Homework & Coursework Questions

if/elif help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This is my problem for the class. Write a script that asks for the user's age. If it is equal to or higher... (6 Replies)
Discussion started by: aggie6970
6 Replies

6. Shell Programming and Scripting

If -elif-else error.

I am getting below error from this code (which is at line 24): if ] #this is line24 in code then mv $File_source_path/$File_name $File_name'_'`date '+%d%m%y'` Error: line 24: Any help with the syntax. I am putting 2 condition with 'AND' clause. This is bash shell. (2 Replies)
Discussion started by: amit.mathur08
2 Replies

7. Shell Programming and Scripting

Query on If-Elif!!

Script Gurus, Need your help in getting this script to come out of logical error : I have pasted the script below: This script finds disk utilzation ... the script is written for both AIX and SUN OS... and option will be given in the initial to select DB or Non DB... its required for my prj...... (1 Reply)
Discussion started by: vangalli
1 Replies

8. UNIX for Dummies Questions & Answers

Help with ELIF statement

I am receiving an elif error on line 13 and I can not figure out the reasoning behind it. I have added the then statement that I was initially missing. Any help would be great. #The purpose of this script is for the end user to be able to enter a positive number #User enters a number NUM=$1... (4 Replies)
Discussion started by: Brewer27
4 Replies

9. Shell Programming and Scripting

If..elif..else...fi

Hi all, I got some problems on executing the following scripts. Scripts: if ]; then echo "M${str}O 0 1" >> ${tempFile} elif ]; then echo "M${str}O 1 0" >> ${tempFile} else echo "M${str}O 0 0" >> ${tempFile} fi Error: "`;' is not expected." what's the problem? (2 Replies)
Discussion started by: Rock
2 Replies

10. Shell Programming and Scripting

elif not expected

Hi, I have a shell script which runs fine when i do it from Unix simulator on Widnows. When i try to run the same for Unix it throws me the error syntax error at line 87: `elif' unexpected. Piece of code for the same is while do if ; then shift configFile="$1"... (9 Replies)
Discussion started by: pv0428
9 Replies
Login or Register to Ask a Question