branching in scripts

I have this script where I need to test for the existance of three different files.
Anyone of the three files can be missing so I need to check for all possibilities. Once I find the correct combination, how do I skip or branch off avoiding the rest of the tests and continue on with the rest of the script. I looked up the exit or goto function but the manual is pretty vague. It doesn't really say how to insert labels. Help
scuzz1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Which scripting language?
0
scuzz1Author Commented:
I need to know for sh (not csh or ksh).
0
chris_calabreseCommented:
sh does not have goto's and labels.  Meanwhile, the traditional way to do this sort of thing is with an if-else construct.  In sh, this would look something like

if [ test condition ]
then  do some stuff
elif [ other condition ]
then  do some other stuff
elif [ yet another condition ]
then  do yet different stuff
fi

mainline code goes here


Alternately, if you really need to do stuff between the if's, you could do some kind of hack like this:

while true
do  if a
      then ...
              break
      fi
      ...
      if b
      then ...
              break
      fi
      ...
      if c
      then ...
              break
      fi
      break
done

mainline code goes here


The 'break' statements will break out of the loop, so you'll never execute it a second time.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

ahoffmannCommented:
or:

if [ ! test condition ] ; exit
0
scuzz1Author Commented:
chris,

 I am using the if statements in this script. It is possible though that finding condition "A" true when it continues on down say to condition "C" it will find condition "C" true also. That is where the problem is. This will result in a file name appearing in a spawned text file twice. I need to be able to bounce by the other if statements but stay in the while loop.

0
ozoCommented:
    if list then list [ elif list then list ] ... [ else list ] fi
          The list following if is executed and, if it returns a zero exit
          status, the list following the first then is executed.  Otherwise,
          the list following elif is executed and, if its value is zero, the
          list following the next then is executed.  Failing that, the else
          list is executed.  If no else list or then list is executed, then
          the if command returns a zero exit status.
0
ahoffmannCommented:
>  I need to be able to bounce by the other if statements but stay in the while loop.
hmm, you match condition A and also C, but you do not want to execute statements for C. If it A and D matches, do you want to execute D? or if A, C and D matches, what should be done?

Sounds that you're looking for something like a stated loop. If so, I recommend to switch to csh (or tcsh, or zsh), which has goto. Otherwise you have to use, and check, a couple of variables.

Please enlight me which combinations of conditions are possible, and which should perform your statements.
0
chris_calabreseCommented:
Sounds to me like the if/elif/else construct I originally suggested would work just fine.  Please test whether this is true before rejecting my answer again.  Such code inside a while loop would look something like



while condition
do  if A
      then
             some stuff that's executed when A is true
      elif B
      then
             some stuff that's executed if A is not true and B is
      elif C
      then
            some stuff that's executed if both A and B are not
            true and C is
      else
           some stuff that's executed if A B and C are all not true
      fi
      some stuff that's executed regardless of A B and C
done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scuzz1Author Commented:
I got it.

I had to embed some more if statements inside of the original if statement (if that makes any sense). I was having problems with the if and elif statements. That last little syntax chris wrote helped me out.

                                                              Thanks :)
                                                              Jim (scuzz1)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.