# Implement a bash shell script that prints the result of the sum of a set# of numbers passed to the script as a command line argument.# A number of equivalent solutions have been proposed. The differences between# them consists on the way used to iterate between program arguments.# Example:# $ ./bash_ex3.sh 2 3 4 5 6# 1) Arguments: 2 3 4 5 6 Sum: 20# 2) Arguments: 2 3 4 5 6 Sum: 20# 3) Arguments: 2 3 4 5 6 Sum: 20#!/bin/bash# First solutionfinal_sum=0echo-n"1) Arguments: "# The variable $* contains all the program arguments with the exclusion of # the program namefor a in$*doecho-n"$a "final_sum=$[$final_sum+$a]doneecho" Sum: $final_sum"# Second solutionfinal_sum=0echo-n"2) Arguments: "# echo writes content of the variable $* to the screen# The symbols ` ` represents the output of the commandfor a in`echo$*`doecho-n"$a "final_sum=$[$final_sum+$a]doneecho" Sum: $final_sum"# Third solutionfinal_sum=0echo-n"3) Arguments: "# The code $(command) corresponds to `command`for a in $(echo$*)doecho-n"$a "final_sum=$[$final_sum+$a]doneecho" Sum: $final_sum"

If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it