[: !=: unary operator expected

In bash, always use the dou­ble bracket con­di­tional com­mand [[ ... ]]

For exam­ple,

#!/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...