Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Created May 8, 2016 07:14
Show Gist options
  • Save complxalgorithm/315ac81b61e4a7a358a260b99b6a02f2 to your computer and use it in GitHub Desktop.
Save complxalgorithm/315ac81b61e4a7a358a260b99b6a02f2 to your computer and use it in GitHub Desktop.
Bash script that will accept 5 input values and find the sum of them.
#!/bin/bash
declare -i counter sum
declare -a -i var
declare -a order
order=([0]="first" [1]="second" [2]="third" [3]="fourth" [4]="fifth")
counter=0
sum=0
while(($counter < 5))
do
echo "Enter the ${order[$counter]} number to add:"
read var[$counter]
sum+=var[$counter]
((counter+=1))
done
echo "The sum of the elements you entered is : $sum"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment