#!/bin/bash
##############################################################
# File Name:/server/scripts/maopaopao.sh
# version:v1.0
# Author: Cattle Farming
# Created time:2017-09-20 19:44:10
# Description: Bubble sort
# Read Instructions:
# 1, read-a shuzu-a indicates that the next input is an array Shuzu is the array name set
# 2, ${#. [@]} The number of elements representing the array
# 3, ${. [@]} Represents all elements of an array
# 4 、.. [A] represents the first element of an array
##############################################################
echo "Please enter a number of numbers:"
Read-a Shuzu #获得数列
For ((a=0;a<${#shuzu [@]};a++)) #循环条件, A=0;a is less than the number of sequence elements, a++
Do #干
For ((b=0;b<${#shuzu [@]}-1;b++)) #
Do #干
if [[${shuzu[b]}-gt ${shuzu[b+1]}]];then #如果 the second element of the sequence is greater than the first B+1 element of the sequence is then
C=${SHUZU[B]} #将数列的第b个元素的的值赋给c
SHUZU[B]=${SHUZU[B+1]} #将数列第b + 1 elements assigned to the B element of the sequence
shuzu[b+1]= $c #将c的值赋给数列的第b + 1 elements The three steps are to swap the numbers in place
Fi #果如
Done
Done #干完了一个循环, back to for continue
echo ${shuzu[@]} #显示 all the elements inside the sequence
Cow farming learning shell bubble sort