我怎样才能得到两个数字的绝对差?

San*_*J R 1 python bash shell awk

是否有任何 bash/shell 命令来获得两个数字的绝对差异?例如。-

-10 and -5 is 5, -10 and 10 is 20, 7 and 21 is 14& 的绝对差异100 and -11 is 111。

或者有什么解决方法可以找到它?请帮忙。

mid*_*ori 6

这是一个简单的:

echo $(($1-$2)) | sed 's/-//'
./script.sh -10 -5
Run Code Online (Sandbox Code Playgroud)

输出

5
Run Code Online (Sandbox Code Playgroud)

逻辑很简单。你提供参数$1和$2你的脚本 ./script.sh -10 -5,然后输出$1 - $2using 的结果echo。如果出现sed 将删除-。