【发布时间】:2015-04-10 15:01:24
【问题描述】:
我正在编写一个 bash 脚本,该脚本将在批处理过程中添加用户。这段代码如下:
#!/bin/bash
# A script that creates users.
echo "This is a script to create new users on this system."
echo "How many users do you want to add?"
read am
echo " "
for i in {0..$am..1}
do
echo "Enter a username below:"
read usern
sudo useradd $usern
sudo passwd $usern
echo " "
echo "User $am '$usern' added."
done
在这种情况下,我想创建 4 个用户。我通过并输入用户名“callum3”并将密码设置为“1234”以便于登录。一旦我输入所有内容(正确,我可以添加),终端窗口将显示以下内容。
User 4 'callum3' added.
这表明我的 for 循环实际上并没有工作,而我看不出它有什么问题。我尝试过使用 while 循环,但也没有运气。
我在这里犯了一个新手错误还是有更深层次的事情发生?
【问题讨论】:
标签: linux bash shell scripting