if statement negation

Hi all,

I've been searching the internet and can't find an answer to this. Im trying to figure out how to negate a whole expression befor an if. I'll explain below.

Let's say

x=0
y=1

[[ x = 0 && y = 0 ]] (this is false) I would like to negate this whole boolean condition. To negate the above expression in other languages I can do something like this

![[ x = 0 && y = 0 ]] returns true

is there something similar in UNIX?

I tried

if ![[ x = 0 && y = 0 ]]; then

............

fi

but this doesn't work it doesn't go into the if statement.

Thanks

There needs to be a space between the ! and the first [

Dont forget the $ in front of variable names and space after !

if ! [[ $x = 0 && $y = 0 ]]; then

or

if [[ ! ($x = 0 && $y = 0) ]]; then

Also in square brackets in bash and ksh93 double == are preferred for a string comparison in combination with double brackets..

if ! [[ $x == 0 && $y == 0 ]]; then

Numerical comparison:

if ! [[ $x -eq 0 && $y -eq 0 ]]; then

Arithmetic evaluation:

if ! (( x == 0 && y == 0 )); then

Or POSIX tests (works in many other shells):

if ! ( [ "$x" = 0 ] && [ "$y" = 0 ] ) ; then
if ! ( [ $x -eq 0 ] && [ $y -eq 0 ] ) ; then

assuming x and y as positive numeric, this will return true if either x or y != 0 :

if ((x+y)); then