Logical Operators

 

Logical Operator

Description

&&

Logical AND: True if both conditions on either side of the operator are true.

!

Logical NOT: Negates the condition, making it true if the condition is false and vice versa.

-a

Logical AND: True if both conditions are true. This is deprecated; use && instead.

-o

Logical OR: True if at least one of the conditions is true. This is deprecated; use `

 

 Logical AND (&&):

if [[ -f "$file" && -r "$file" ]]; then

    echo "The file exists and is readable."

fi

Logical OR (||):

if [[ -z "$var" || "$var" == "default" ]]; then
    echo "The variable is either empty or set to 'default'."
fi


Logical NOT (!):

if [[ ! -f "$file" ]]; then
    echo "The file does not exist."
fi

Comments

Popular posts from this blog

AWK : Commands

CURL Commands

$$$$ Symbols in shell scripting