#!/bin/bash
# PROBLEMS shown:
# - command line parameters
# - arithmetic operations
# - various types of for cycles
# - use of variable content (from the command line and as an array)
# - array

LIMIT=$#
final_sum=0
# the -n in the echo to not include a \n at the end of the line
# attention to double (( and to LIMIT WITHOUT $
echo -n "The command row contained: "
for ((a=1; a <= LIMIT ; a++)) 
do
   echo -n "${!a} "
   let "final_sum += ${!a}"
done  
echo

echo "The sum of the numbers passed on the command\
row is $final_sum."

# the same thing can be done with
echo -n "Here are the same data obtained in another way: "
for a in "$@"
# parameters on the command line are passed one at a time
do
   echo -n "$a "
done  
echo

# the same thing can be done with
echo -n "Here are the same data obtained in a third way: "
for a in `echo "$*"`
# attention with the accents that open and close the previous echo command
do
   echo -n "$a "
done  
echo

# the same thing can be done with
echo -n "Here are the same data obtained in a fourth way: "
for a in $(echo "$*")   
# NOTICE: in $( ) there is a command! (as for ` `)
do
   echo -n "$a "
done  
echo

# to finish we can use arrays
echo -n "The content of the array is: "
for ((a=1; a <= $# ; a++))
do
   vector[$a]=${!a}
   echo -n "${vector[$a]} "
done
echo
