What does linux eq mean?

藏色散人
Release: 2023-03-23 09:43:17
Original
3269 people have browsed it

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
Copy after login

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
Copy after login

Run the test

>bash eq.sh
Copy after login

The results are clear at a glance

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

Conclusion:

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

The difference between !=, >, <, >=, <= 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template