gpt4 book ai didi

linux - shell 中的整数加法

转载 作者:IT王子 更新时间:2023-10-29 00:22:06 25 4
gpt4 key购买 nike

这是我的简单 shell 代码。我希望结果为 2。Shell 将所有内容都视为字符串。我怎样才能完成这项工作?

num=1
num=$(( $num + 1 ))

编辑:

完整代码:如果我想打印 1 到 10,这有什么问题?

#! /bin/bash

num=1
until test $num -eq 10
do
num=$(( $num + 1 ))
echo $num
done

最佳答案

bash 中,您不需要做任何特别的事情:

aix@aix:~$ num=1
aix@aix:~$ num=$(( $num + 1 ))
aix@aix:~$ echo $num
2

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

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