When looping through this while loop, I get to the first if condition which happens to be true. It should not get to any of the other elif conditions, right? I'm looping through a file and if the line doesn't have a ';' at the end, I want to log a message and go to the next line.
Also, can someone explain the significance of the brackets? It behaves differently if I have one or two brackets around a condition.
<code>
cat $LOGGING_INFO_FILE | while read LINE
do
firstChar=`echo $LINE | cut -f1 -d "/"`
if [[ $firstChar = "." ]]; then
restOfLine=`echo $LINE | cut -f2 -d "."`
echo " " >> $LOG_OUTPUT_FILE
echo $restOfLine >> $LOG_OUTPUT_FILE
echo "*************************
**********
**********
**********
**********
" >> $LOG_OUTPUT_FILE
else
errorCodeLine=`echo $LINE | cut -f4 -d "," | cut -f1 -d ")"`
errorCode=`echo $LINE | cut -f4 -d "," | cut -f2 -d "." | cut -f1 -d ")"`
errorCodeFile=`echo $LINE | cut -f4 -d "," | cut -f1 -d "." | cut -f1 -d ")"`
lastChar=`echo $LINE | tail -2c`
commaCount=$((`echo "$LINE" | sed 's/[^,]//g' | wc -c` - 1 ))
count=0
count=`grep -ic $errorCodeLine $LOGGING_INFO_FILE`
if [[ $lastChar != ";" ]]; then
echo "This file contains a carriage return in the TEHelper.logMessage(). Please remove all carriage returns." >> $LOG_OUTPUT_FILE
hasError=1
elif [ commaCount -gt 3 ]; then
echo "This file contains comma's in TEHelper.logMessage(). Please remove all comma's from first parameter" >> $LOG_OUTPUT_FILE
hasError=1
elif [ $errorCodeFile != $ICNEC ]; then
echo "INVALID ERROR CODE -->" $errorCode " is not valid" >> $LOG_OUTPUT_FILE
hasError=1
elif [ $count -gt 1 ]; then
echo "ERROR CODE IS USED " $count " times -->" $errorCode >> $LOG_OUTPUT_FILE
hasError=1
fi
fi
</code>
Thanks,
Skip
Start Free Trial