What does linux eq mean?

藏色散人
藏色散人Original
2023-03-23 09:43:173296browse

linux eq means "equal to". It is a comparison operator in Linux, used to determine whether the numerical values ​​corresponding to strings are equal; the use of this operator is such as "if [ $num1 - eq $num2 ] then echo "$num1 and $num2xiangdeng" else echo "$num1 and $num2buxiangdeng"".

What does linux eq mean?

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

linux What does eq mean?

linux eq (equal) is a comparison operator.

The difference between "==" and "-eq" in the linux shell (bash) test expression

First of all, we must understand a concept: all variables in bash are strings. When performing numerical calculations on variables, it is nothing more than temporarily converting a string into a number, then calculating, and then converting the resulting number into a string after calculation.

Let’s talk about the difference between "==" and "-eq"

"==" is to determine whether the strings are equal.

"-eq" is to determine whether the numerical values ​​corresponding to the strings are equal.

for example.

Create eq.sh script

>vi eq.sh

The content is as follows

#!/bin/bash
num1=123 #num1是长度为3的字符串
num2=0123 #num2是长度为4的字符串

echo "======================================"

echo -n "用==比较时:"
if [ $num1 == $num2 ]
then
echo "$num1和$num2相等"
else
echo "$num1和$num2不相等"
fi

echo "======================================"

echo -n "用-eq比较时:"
if [ $num1 -eq $num2 ]
then
echo "$num1和$num2相等"
else
echo "$num1和$num2不相等"
fi

Run the test

>bash eq.sh

The results are clear at a glance

======================================
用==比较时:123和0123不相等
======================================
用-eq比较时:123和0123相等

Conclusion:

== Compare strings directly, -eq compares the numeric value corresponding to the string.

The difference between !=, >, 95ec6993dc754240360e28e0de8de30a=, <= and -ne, -gt, -lt, -ge, -le and so on

Related recommendations : "Linux Video Tutorial"

The above is the detailed content of What does linux eq mean?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is linux ppc64Next article:What is linux ppc64