gpt4 book ai didi

linux - linux shell 中的减法 if

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:43 26 4
gpt4 key购买 nike

在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com