case $HOSTNAME in (*q20*) alias a='cd ~/a1';; (*) alias a='cd ~/a99'; esac
You're getting an error, because spaces are missing after [[ and because -z is to test if a particular string is empty. [[ is a non-standard feature, how it behaves depends on the version of bash. The case structure is POSIX and as written will work in any POSIX shell and any version of bash.
More generally, it's also better to stay away from things like cmd1 && cmd2 || cmd3 as it generally doesn't not do what you want if cmd2 fails.
Also, I don't see the point in putting it all on one line. That's something that's going to go to some rc file, right? Then it will be a lot more legible if on several lines.
case $HOSTNAME in
(*q20*) alias a='cd ~/a1';;
(*) alias a='cd ~/a99'
esac
is more legible and portable than:
if [[ $HOSTNAME =~ q20 ]]; then
alias a='cd ~/a1'
else
alias a='cd ~/a99'
fi
itself more legible (and more correct) than:
[[ $HOSTNAME =~ q20 ]] &&
alias a='cd ~/a1' ||
alias a='cd ~/a99'
itself more legible than
[[ $HOSTNAME =~ q20 ]] && alias a='cd ~/a1' || alias a='cd ~/a99'