Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SUM() {
- echo "The sum is $(($1+$2+$3+$4+$5+$6+$7+$8+$9))"
- }
- SUM 3 8
- bash: 3+8+++++++: syntax error: operand expected (error token is "+")
- sum() {
- [[ -n $2 ]] && echo $(( $(tr ' ' '+' <<<"$@") ))
- }
- $ sum 1 2 3
- 6
- sum() {
- [[ -n $2 ]] && (IFS=+; echo $(( $* )))
- }
- SUM() {
- echo "The sum is $(($1+$2+${3:-0}+${4:-0}+${5:-0}+${6:-0}+${7:-0}+${8:-0}+${9:-0}))" || false
- }
- SUM() {
- echo "The sum is $(($1+$2+${3:=0}+${4:=0}+${5:=0}+${6:=0}+${7:=0}+${8:=0}+${9:=0}))" || false
- }
- sum () {
- local total=0;
- while [ $# -gt 0 ]; do
- total=$(($total + $1))
- shift
- done
- echo $total
- }
- sum () {
- test $1 && echo $(( $1 + $(shift; sum $@) )) || echo 0
- }
- SUM () {
- [ $# -lt "2" ] && return 1
- for par in $@; do
- local sum=`expr $sum + $par`
- done
- echo $sum
- return 0
- }
- SUM 3 4 5
- SUM 3 4 5 1 1 1 1 2 3 4 5
- sum(){
- t=0;
- for i in "$@"; do t=$((t + i )); done
- echo $t;
- }
- sum(){
- echo "$@" | perl -lane '$s+=$_ for @F; print $s'
- }
- sum(){
- echo "$@" | awk '{for(i=1; i<=NF; i++){k+=$i} print k}'
- }
- SUM() {
- echo "The sum is $(($1+$2+$[$3]+$[$4]+$[$5]+$[$6]+$[$7]+$[$8]+$[$9]))"
- }
- $ SUM 4 6 5
- The sum is 15
- SUM() {
- echo "The sum is $((${1:-0}+${2:-0}+${3:-0}+${4:-0}+${5:-0}+${6:-0}+${7:-0}+${8:-0}+${9:-0}))"
- }
- ${parameter:-word}
- Use Default Values. If parameter is unset or null, the expansion
- of word is substituted. Otherwise, the value of parameter is
- substituted.
- $ SUM
- $ SUM 1 2
- $ SUM 1 1 1 1 1 1 1 1 1
- SUM() {
- echo -e ${@/%/\n} | awk '{s+=$1} END {print "The sum is " s}'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement