35

I want to ask is it possible to give multiple statements to be executed when if condition gets satisfied by doing just

if[condition] then
statements
else
statements
fi

or we have to do something else like using do.....done around that block of statements

1
  • Why not just try it out and see what happens? Commented Nov 29, 2022 at 8:27

1 Answer 1

56

Yes you can have multiple statements:

if [ condition ]; then
  echo 'foo'
  echo 'bar'
else
  echo 'hello'
  echo 'world'
fi
Sign up to request clarification or add additional context in comments.

1 Comment

FWIW to Shweta, the statements can also be separated by semicolons.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.