0
您好,我需要制作一个bash脚本,它将从文件中读取数据,然后在文件中添加数字。例如,文件即时阅读会为已读:bash脚本读取文件中的数字
猫samplefile.txt
1
2
3
4
脚本会使用文件名作为参数,然后添加这些数字并打印出总和。我坚持如何从文件中读取整数,然后将它们存储在一个变量中。 到目前为止,我拥有以下内容:
#! /bin/bash
file="$1" #first arg is used for file
sum=0 #declaring sum
readnums #declaring var to store read ints
if [! -e $file] ; do #checking if files exists
echo "$file does not exist"
exit 0
fi
while read line ; do
do < $file
exit