linux shell脚本退出一次到达代码中的某个点

时间:2015-09-02 16:46:27

标签: linux shell raspberry-pi sh raspbian

当我的代码达到某一点时,它会关闭但没有完成。它为什么这样做?顺便说一句,它确实创建了用户并将其分配给组;一旦您在提示您该组不存在并且您想要创建它之后输入y,那么终端将关闭,并且不会继续使用其余代码。

#!/bin/bash
let repeat=1
let counter=0
while [ $repeat -eq 1 ];
        do
        echo "Please enter the username for the created user"
        read username
        sudo useradd -m $username
        echo ""
        sudo passwd $username
        let counter=$counter+1
        while [ $repeat -eq 1 ];
                do
                echo "please enter the name of the group to put the user into"
                read group
                if [ $(getent group $group) ]; then #line 17 
                        sudo usermod -G $group,sudo $username
                        let repeat=0
                else
                        echo "The group "$group$" does not exist on our system"
                        echo "Do you want to create it as a new group (y)"
                        read input
                        if [ [ $input == "y" ] ]; then
                                sudo groupadd $groups
                                sudo usermod -G $group,sudo $username
                                let repeat=0

                        fi

                fi

         done
         echo $username" has beem added to the group "$group
   done
   echo "You have now created "$counter" new user(s) and have added them to   their new group(s)"

0 个答案:

没有答案