#!/bin/bash MODULE_NUM=1 MODULE_MAX_NUM=5 WORK_PATH=/root/shell/workspace #add module add() { installNum=$MODULE_NUM if [ -z $2 ]; then echo "install default number : $MODULE_NUM" else installNum=$2 fi if [ $installNum -gt $MODULE_MAX_NUM ]; then installNum=$MODULE_MAX_NUM fi echo "install number is $installNum" for i in $(seq 1 $installNum); do do_add $i done } #do the add operation do_add() { if [ ! -e $WORK_PATH/test$1 ]; then mkdir $WORK_PATH/test$1 echo "add test$1" fi } #do the remove operation do_remove() { if [ -d $WORK_PATH/test$1 ]; then echo "remove module $1" rm -rf $WORK_PATH/test$1 fi } #remove all modules remove() { #echo "remove all modules" for((i=1;i<=$MODULE_MAX_NUM;i++)); do if [ -e $WORK_PATH/test$i ]; then do_remove $i fi done } #modify modules number modify() { modNum=$2 echo modify modules number to $2 for((i=$MODULE_MAX_NUM;i>$2;i--)); do #echo "remove module $i" do_remove $i done if [ $modNum -gt $MODULE_MAX_NUM ]; then modNum=$MODULE_MAX_NUM fi for((i=1;i<=$modNum;i++)); do #echo "add module $modNum" do_add $i done } #main process case $1 in add) add $1 $2 ;; rmv) remove $1 ;; mod) modify $1 $2 ;; *) echo -e "bad parameter, usage : balabala..." ;; esac