Maw*_*ter 0 linux math bash scripting
所以我只是在研究一些简单的算术代码.这是我得到的:
echo "The number should be 2";
declare -i input added
input= date +%w
let added="input/2"
echo "$added"
Run Code Online (Sandbox Code Playgroud)
当我运行它时输出是
4
0
Run Code Online (Sandbox Code Playgroud)
我想要得到2.我到底做错了什么?
问题是你如何创建input变量.它只是执行命令,但没有将结果分配给input.相反,做:
input=$(date +%w)
Run Code Online (Sandbox Code Playgroud)
这将分配date命令的输出input.