我想将新帐户的密码设置为用户输入的输入(字符串)。这似乎不起作用。顺便说一句,这是一个更大的脚本的一部分,我只包含了这个问题的相关部分。
因此,如果我运行代码,我会收到以下错误代码:/create-user.sh: line 36: user3:hej: command not found。这里的行不同,因为它是更大脚本的一部分。上面的“hej”是我在运行代码时输入的密码。我猜shell认为“hej”应该是一个命令,但它应该是一个密码字符串。澄清一下,hej 应该是密码。
#!/bin/bash
# Get the username (login).
read -p "Please enter a username: " username
# Get the password.
read -p "Please enter an initial password: " password
# Create the account.
useradd "$username"
# Set the password.
chpasswd | "$username":"$password"