linux - 如何在 bash 命令 "<=,>="中使用 "[[ ]]"?

标签 linux bash shell command

<分区>

我是 bash 的新手。当我尝试使用命令 [[为了比较,我遇到了如下问题:

enter image description here

[root@JD ~]# [[ 2 <= 2 ]]
-bash: syntax error in conditional expression
-bash: syntax error near `2'

来 self 的教程书,[ 2 -le 2 ]应该等于 [[ 2 <= 2 ]] ,我不知道为什么是语法错误。

最佳答案

在双方括号中,<=不是公认的运营商。 <>无论如何,都用于比较字符串。使用 -le对于数字,或切换到使用圆括号的算术表达式:

(( 5 <= 10 ))

关于linux - 如何在 bash 命令 "<=,>="中使用 "[[ ]]"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50886541/

相关文章:

c - 如何确定 netsnmp 代理的 IP 和 MAC 地址?

bash - 使用 bash,您使用哪些脚本或命令来提高工作效率?

linux - crontab 在调用包含输出的 .sh 时不输出任何内容

java - 编译错误java hadoop程序

linux - 密码的 key 大小是什么意思

git - Meteor:调用方法执行shell(克隆git repo)

linux - "Permission denied"启动时运行命令

c# - 尝试从 Chrome 实现拖放 Gmail 附件

php - php 中的 chmod 777

mysql - 截断两个日期之间的表(使用 MySQL 和 bash 脚本)