#!/bin/bash # Bubble Sort echo "Input unsorted numbers --" read -a num numlen=${#num[*]} # Sort the array x=$numlen temp=0 # Standard algorithm for bubble sort while [ $x -gt 0 ]; do i=0 while [ $i -lt $[$numlen-1] ]; do j=$[$i+1] # If the previous element in the array is greater than the next then swap the # values. if [ ${num[i]} -gt ${num[j]} ] then temp=${num[i]} num[i]=${num[j]} num[j]=$temp fi i=$j done x=$[$x-1] done # Display the sorted array echo "Sorted Output --" echo ${num[*]}