linux - linux shell 中的减法 if

标签 linux bash shell

在 linux bash shell 中,如何在 if 中从另一个变量中减去一个变量?我尝试了以下方法:

#!/bin/bash
start=0
end=1
if [ end - start -eq 1 ]; then
    echo "right"
fi

它不起作用。

最佳答案

既然你特别提到了bash,那就用它的算术支持吧:

#!/bin/bash
start=0
end=1
if ((end - start == 1)); then
    echo "right"
fi

关于linux - linux shell 中的减法 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32545247/

相关文章:

捕获终端的强制退出(顶部的 x 按钮或 ctrl+Z)

linux - 检查目录树中文件时间戳的快速方法

linux - uuencode 无法正常使用我的以下命令附加文件

bash 脚本使用单词指示符和单词修饰符来自动化 wget tar cd

linux - 分析wget命令的返回值

c - 使用 ncurses 在 pads 中包装文本。 (在 C 中)

linux - 抄送: unrecognized option '-KPIC'

c - 确定驱动模块所在的位置(内存地址)

bash - IFS 在 bash 中按预期工作,但在 zsh 中无法正常工作

python - 将 HISTFILE 设置为命名管道