linux - shell 脚本 "test "命令

标签 linux shell

我正在编写 shell 程序来比较两个数字并使用测试命令显示状态

#!/bin/sh
a="42"
b="23"
echo $a
test [$a -eq $b]
echo $?

但是我遇到这样的错误 eq: line 5: test: [42: integer expression expected 2

最佳答案

你必须换行

test [$a -eq $b]

test $a -eq $b  

测试需要一个整数表达式,而 [$a -eq $b] 不是一个整数表达式

关于linux - shell 脚本 "test "命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56679441/

相关文章:

linux - 命令 'cut' 不显示最后一列 CSV

C: stdout 挂起 linux 管道

linux - 如何检测当前是否对 linux 上的文件进行了文件操作

c - 统一认证库

c++ - 如何在没有OOM killer 的情况下发出C++终止捕获

linux - 在 Linux 系统上,除了使用 "cgroups"之外,还有什么方法可以限制正在运行的进程的内存使用量吗?

bash -/usr/bin/重命名 : Argument list too long (mass renaming files)

python - 在 Jupyter 中运行 for 循环终端命令

shell - Ansible - 当至少一个项目在循环中失败时跳过任务

shell - 比较 Busybox ash 中的子字符串