4

I have a bash script and I have an else statement which I want it to do nothing.

What is the best way to do this?

17

The standard way to do it is using colon ::

if condition; do
  command
else
  :
fi

or true:

if condition; do
  command
else
  true
fi

But why not just skipping the else part:

if condition; do
  command
fi

In zsh and yash, you can even make the else part empty:

if condition; then
  command
else
fi
6

The else statement is optional. Just type:

if [ expr ]; then
#bla
#bla
#bla
fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.