Shweta
Shweta

Reputation: 5446

Multiple statements in if else statement in shell scripting

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

Upvotes: 34

Views: 52915

Answers (1)

codaddict
codaddict

Reputation: 454960

Yes you can have multiple statements:

if [ condition ]; then
  echo 'foo'
  echo 'bar'
else
  echo 'hello'
  echo 'world'
fi

Upvotes: 54

Related Questions