Index of Highest Value Script

Script Requirements

  • Write a script that does the following:
    • Loops through an ArrayList
    • Prints out the highest number within the list
    • Prints out the index of the highest number
Click Here for Solution
#!/bin/bash

## Enter any numbers inside of index_list
index_list=(15 10 -3 5 23 -5)

for number in ${!index_list[@]}
do
	if [[ ${index_list[$number]} -gt $high_value ]]
	then
		high_value=${index_list[$number]}
		high_index=$number
	fi
done

echo "The highest value within the array is: "$high_value
echo "The index location of the highest value is: "$high_index