I have a logic like this
It initializes the flag variable as "T" at the beginning of the loop everytime
Inside each loop it checks for two conditions and updates the flag variable as "A" or "B"
In the end of the loop it checks for the value of the variable flag for "A" or "B" and execute different steps
This is not working as expected.What is the scope of the flag variable??
for filename in `<command will get list of files>`
do
flag="T"
if [ <checks for a condition A> ]
then
echo "Correct"
else
flag="A"
fi
if [ <checks for a condition B> ]
then
echo "Correct"
else
flag="B"
fi
if [[ flag == "A" || flag == "B" ]]
then
echo " Do nothing "
else
echo "Execute steps for flag T"
fi
done
What does "not working" mean? What happens? Why do you think that is not right?
Please put code inside
tags and use indentation to show the structure of your script.
for filename in `<command will get list of files>`
[/quote]
[indent]
Be careful using a command to get a list of filenames; it can break very easily if any filenames contain spaces or other patholigical characters.
Whenever possible, use wildcards.
You never check whether the value is "T", so why bother setting it?
[[ ... ]] is non standard, as is ==. For portability, use (and don't forget to use a (quoted) variable instead of the literal "flag"):