mooc/filesystem/home/carole/A45/sum.sh

22 lines
309 B
Bash
Raw Normal View History

2023-01-31 08:45:52 +04:00
#!/bin/bash
#=============== function
function add
{
echo $(cat $@) | tr ' ' '+' | bc
}
#=============== main
if [ $# -gt 0 ] ; then
for item
do
if [ ! -f $item ]
then
echo "ERROR: $file doesn't exist" >&2
exit 1
fi
done
sum=$(add "$@")
else
sum=$(add - )
fi
echo "sum = $sum"
exit 0