shell递归一例

Posted by 4Aiur on 03/31/2010 in Shell |

用递归写的一个光标旋转的小脚本
[root@maint-app-108 recurse]# cat cursor.sh

cursor () { #{{{
   message="$1"
   count="$2"
   for item in "|" "/" "-" "\\"
   do
       printf "\r${item} ${message} $count"
       usleep 50000
   done
   cursor waiting $((count+1))
}

cursor waiting 1

[root@maint-app-108 cursor]# 用递归做这种无限循环最后脚本会退出,下面这个while :不会退出。 [root@maint-app-108 cursor]# cat cursor.sh

cursor () { #{{{
   message="$1"
   for item in "|" "/" "-" "\\"
   do
       printf "\r${item} ${message}"
       usleep 50000
   done
}

while :
do
   cursor waiting
done

Tags:

Copyright © 2010-2024 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.