for digit in "$@"
do
sum=`expr $sum + $digit`
done
echo "The Sum of $* is $sum";
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./sumOfCmdDigits.sh 1 2 3 4 5
#The Sum of 1 2 3 4 5 is 15
#root@slack-linunx:~/scripts#
sum=0;
do
sum=`expr $sum + $digit`
done
echo "The Sum of $* is $sum";
OUTPUT:-
#!/bin/bash
#root@slack-linunx:~/scripts# ./sumOfCmdDigits.sh 1 2 3 4 5
#The Sum of 1 2 3 4 5 is 15
#root@slack-linunx:~/scripts#
sum=0;
0 comments:
Post a Comment