码迷,mamicode.com
首页 > 系统相关 > 详细

shell

时间:2017-02-13 00:32:18      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:shell   shell数组   利用数组实现排序   

通过脚本时间对数排序

#执行脚本:sh ./paixu.sh 88 99 55 44 66

实现效果: 44

      55

      66 

      88

      99 

#!/bin/bash

#filename:paixu.sh

i=1

w=$#

for N in $*;do

    a[$i]=$N

    let i++

done

p=1

while [ $p -le $w ];do

    q=$p

    while [ $q -le $w ];do

          f=$(($q+1))

          m=${a[$p]}

          n=${a[$f]}

    if [[ $m -lt $n ]];then

          a[$p]=$n

          a[$f]=$m

    fi

          let q++

    done

    let p++

done

j=$w

while [ $j -ge 1 ];do

echo  "${a[j]}"

  let j--

done


本文出自 “linux学习成长过程” 博客,谢绝转载!

shell

标签:shell   shell数组   利用数组实现排序   

原文地址:http://syuchen.blog.51cto.com/12570224/1897113

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!