Countries=(Netherlands Ukraine Zaire Turkey Russia Yemen Syria \
Brazil Argentina Nicaragua Japan Mexico Venezuela Greece England \
Israel Peru Canada Oman Denmark Wales France Kenya \
Xanadu Qatar Liechtenstein Hungary)
# "Xanadu"虚拟出来的世外桃源.
#+
clear # 开始之前的清屏动作.
echo "0: ${Countries[*]}"# 从索引0开始列出整个数组.
number_of_elements=${#Countries[@]}
let "comparisons = $number_of_elements - 1"
count=1 # 传递数字.
while["$comparisons"-gt 0 ]# 开始外部循环
do
index=0 # 在每轮循环开始之前, 重置索引.
while["$index"-lt"$comparisons"]# 开始内部循环
do if[${Countries[$index]} \>${Countries[`expr $index+ 1`]}] # 如果原来的排序次序不对...
# 回想一下, 在单括号中,
#+ \>是ASCII码的比较操作符.
# if [[ ${Countries[$index]} > ${Countries[`expr $index + 1`]} ]]
#+ 这样也行.
then
exchange $index `expr $index+ 1` # 交换.
fi
let "index += 1"# 或者, index+=1 在Bash 3.1之后的版本才能这么用.