22 lines
309 B
Bash
22 lines
309 B
Bash
|
#!/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
|