Command input from the three numbers in ascending order (bubble sort)
Principle: To compare two adjacent elements, large elements of the right to exchange value.
Script Content:
[@ VM_0_10_centos the root ShellScript] numSort.sh CAT # # ! / bin / the bash # three numbers in ascending order, corresponding to the bubble sort java # from the command line input three numbers Read -p "Please enter an integer : " num1 the Read -p" enter an integer: " num2 the Read -p" enter an integer: " num3 data #define temporary storage of variables tmp = 0 # large number regardless of the input of who who is small, the number of final output must It is num1 <num2 < num3 # the num1 and num2 compared, if num1 is greater than num2, values num1 and num2 the reversed IF [$ num1 - gt $ num2]; the then tmp = $ num1 num1 = $ num2 num2 = $ tmp Fi If greater than num3 # num1, the values num1 and reversed num3 IF [$ num1 - gt $ num3]; the then tmp = $ num1 num1 = $ num3 num3 = $ tmp Fi # If num2 is greater than num3, the value num2 and num3 the reversed IF [$ num2 - gt $ num3]; the then tmp = num2 $ num2 = $ num3 num3 = $ tmp Fi echo "the sorted data (small to large) is: $ num1, $ num2, $ num3"