Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 shell 脚本中,命令输出给出整数,如:
xxx$> xxxx 10 20 30
我想添加这些整数值并获得总和值。最简单的方法是什么..?
假设你的脚本被命名xxxx,你可以这样做:
xxxx
xxxx | awk '{sum+=$1} END {print sum}'
这将打印由 打印的整数的总和xxxx:
~$ xxxx 10 20 30 ~$ xxxx | awk '{s+=$1} END {print s}' 60