bash: if else flow control

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

If then elif else fi

#!/bin/bash

if [ "$1" ]
then
  echo "$1"
else
  echo "error"
fi

Beware on how you validate your variables. See:

Errors

syntax error near unexpected token `else'

Do not forget the then line.