0

I have this code:

for x in 1 2 3;
do
  ./test.sh $x
done

test.sh looks like this

echo "$1"
if [ "$1" = "2" ]
then
  exit 1
else
  exit 0
fi

how do I get it to output only

1
2

Instead of

1
2
3

1 Answer 1

2

break if the test.sh fails:

for x in 1 2 3;
do
  ./test.sh $x || break
done
Sign up to request clarification or add additional context in comments.

2 Comments

thanks. but to add another layer of complexity to the same question, how do I do it with a nested loop, such as this
To ask a new question, create a new question. You can link to the old one if you feel their relation is important.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.