Linux之脚本学习案例

需求:根据输入的游戏区服范围生成所有的区服名称

$ cat ss_v1.sh 
#!/bin/env bash

. /etc/init.d/functions

RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELLOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
RES='\E[0m'

if [ ! $# -eq 1 ]; then        
        echo -e "${GREEN_COLOR}Useage:$0 servers range${RES}"        
        exit 0
fi

args=$1
args_part1=`echo $args | awk -F "-" '{print $1}'`
args_part2=`echo $args | awk -F "-" '{print $2}'`
prefix=${args_part1:0:1}
start_flag=${args_part1:1}
stop_flag=${args_part2:1-0}

#echo ${prefix},${start_flag},${stop_flag}
for i in `seq ${start_flag} ${stop_flag}`
do 
    printf "${prefix}%02d\n" $i
done

$ sh ss_v1.sh s1-s10
s01
s02
s03
s04
s05
s06
s07
s08
s09
s10

 

posted @ 2017-08-25 10:03  每天进步一点点!!!  阅读(196)  评论(0编辑  收藏  举报