ajreal
ajreal

Reputation: 47321

How to skip a particular number when iterate over a range sequence number?

Let's said

for i in {1..9}
do
  if test $i -ne 8
  then 
    echo $i 
  fi
done

If there a way to skip number 8 from this sequence {1..9} without doing the comparison?

PS: GNU bash, version 3.00

Upvotes: 1

Views: 4650

Answers (3)

AnthonyHurst
AnthonyHurst

Reputation: 133

just test if it's the value(s) you don't want and then continue which just finishes this iteration and goes on to the next one.

if $test == 8{
    continue;
}

Upvotes: 0

rodion
rodion

Reputation: 15029

You can safely do:

{1..N} {N+2..P}

Upvotes: 7

ajreal
ajreal

Reputation: 47321

damn... figure it out myself

for i in {1..7} 9

Upvotes: 9

Related Questions