linux shell两个文件数值相加

linux shell两个文件数值相加,第1张

#!/bin/bash

n=1

for i in `cat 1.txt`do # 循环1.txt

num=`sed -n "${n}p" 2.txt` # 获取2.txt对行的数字

sum=$(($num + $i)) # 两数相加

echo $sum # 打印结果

n=$(($n + 1))

done

#!/bin/bash

echo

-n

"Enter

the

first

num:"

read

first

echo

-n

"Enter

the

second

num:"

read

second

sum=$(echo

$first+$second|知bc)

echo

"$first+$second=$sum"

测试没问题!touch

一个文件,然道后vi它,直接vi也可以,然后插入,复制回粘贴,保存退出,更改权限,就可以执行了。答


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8918813.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存