I am trying to write a shell script which has a part where I have to use some kind of loop to execute some commands if condition satisfy.
I want to understand what is the best way to approach this problem.
Lets say there are 3 flags
#export flag1=1
#export flag2=1
#export flag3=1
These are commented in the beginning. While running the script, I want to enable these flags one after the other.
So for that I have written a if else loop in such way.
if [[ -n ${flag1} ]]; then
#some commands
elif [[ -n "${flag2}" ]]; then
#some commands
elif [[ -n ${flag3} ]]; then
#some commands
else
#some commands
fi
But, when I enable flag1 it goes to else loop and it’s giving different result than expected.
What’s the best way to approach this issue?
Should I use case instead of if else loop ?