samedi 29 août 2015

bash and if with multiple logical operands

I am trying to check if 2 variables are empty or not defined at the same time in bash. If that is the case, no user password will be changed.

#!/bin/bash
read -s  -p "Enter root password: " rootpass1
echo
read -s  -p "Enter root password again: " rootpass2
echo

if  [[-z "$rootpass1"] && [-z "$rootpass2"]]
then
    echo "Password will not be changed"
else
    echo "user:$rootpass1" | chpasswd
fi

But I am getting the following error:

script.sh: line 7: [: missing `]'

Any clue?

Aucun commentaire:

Enregistrer un commentaire