We help IT Professionals succeed at work.
Get Started

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

antvu asked
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.


# Access the file and read the content to parse the lines to get all values
echo $myfile
for vars in $myfile
    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
   echo " th value of filetype is $filetype..\n"
   echo " if you are seeing this then the if block is not executed"

Open in new window

Watch Question
Top Expert 2007
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