We help IT Professionals succeed at work.
Get Started

test condition in If ..else.. loop not working

antvu
antvu asked
on
1,711 Views
Last Modified: 2013-12-26
Hello All.

I have a script which basically reads a file and moves the files between 2 directories. I am attaching the code. This script has a for loop which reads a file (a pipe delimited file) and with in the for loop , I have a if and else loop , which is not working..

The for loop is working fine. I echoed all the variables which are output from "awk" commands, but it is the if block that is not executing. It is directly going into else block.

is there any glaring syntax error that i am ovelooking.. please help.

Thanks
Antv

# Access the file and read the content to parse the lines to get all values
myfile="$1"
 
echo $myfile
 
for vars in $myfile
  do
    filenm1=`awk -F "|" '{print $1}' $myfile`
    fileid=`awk -F "|" '{print $2}' $myfile`
    filetype=`awk -F "|" '{print $3}' $myfile`
    filedate=`awk -F "|" '{print $4}' $myfile`
    filnm2=`awk -F "|" '{print $5}' $myfile`
    Incoming_ID=`awk -F "|" '{print $6}' $myfile`
 
# Move the files basefd on filetypes
if [[ "$filetype" = "XYZ" ]]; then
    echo "the value of $filetype \n"
     echo " the filesname to be moved is $filenm2. \n"
     echo " filename1 is $filenm1 ...\n"
    mv -f /home/atc/$filenm2 /work/hold/$filenm1
else
   echo " th value of filetype is $filetype..\n"
   echo " if you are seeing this then the if block is not executed"
fi
done

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2007
Commented:
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE