[: !=: unary operator expected

In bash, always use the double bracket conditional command [[ ... ]]

For example,

#!/bin/bash
sex=male

if [[ $sex == 'male' ]];then
  echo "sex is male."
elif [[ $sex == 'female' ]];then
  echo "sex is female."
else
  echo "Invalid sex."
fi

You may also like...