What does the -eq operator do?

0106

The -eq operator is used in shell scripting (like Bash) to compare two integers for equality. It returns true if the two integers are equal and false otherwise.

Here’s an example:

a=5
b=5

if [[ $a -eq $b ]]; then
  echo "a is equal to b"
else
  echo "a is not equal to b"
fi

In this example, since a and b are both 5, the output will be:

a is equal to b

0 Comments

no data
Be the first to share your comment!