Created
May 8, 2016 07:14
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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