Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if [[ $# < 2 ]]; then
- me=`basename "$0"`
- echo "Usage: ./$me <output file> <arg1> <arg2> ... <argN>"
- exit 1
- fi
- # count even numbers in c
- # sum all numbers in s
- # compute digit count for s in variable d
- filename=$1
- shift
- c=0
- s=0
- for number in "$@" ; do
- (( s += number ))
- if [[ $((number%2)) -eq 0 ]]; then
- (( c += 1 ))
- fi
- done
- d=${#s}
- if [ -f $filename ] && [ ! -L $filename ]; then
- # write c, s and d to file
- echo "count of even numbers is $c" >> $filename
- echo "sum of digits is $s" >> $filename
- echo "digit count for s is $d" >> $filename
- else
- # error
- echo "File does not exist or is not a regular file!"
- exit 1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement