我正在使用Debian。我正在学习Bash脚本。我正在创建一个脚本来创建新用户并设置密码,问题是我遇到passwd: unrecognized option '--stdin'
错误
那是我的剧本:
#!/bin/bash
read -p "Please Enter Your Real Name: " REAL_NAME
read -p "Please Enter Your User Name: " USER_NAME
useradd -c "${COMMENT}" -m ${USER_NAME}
read -p "Please Enter Your Password: " PASSWORD
echo ${PASSWORD} | passwd --stdin ${USER_NAME}
passwd -e ${USER_NAME}
答案 0 :(得分:0)
没有--stdin
选项,您需要用引号保护变量。
这是一个有效的版本:
#!/bin/bash
read -p "Please Enter Your Real Name: " REAL_NAME
read -p "Please Enter Your User Name: " USER_NAME
useradd -c "${COMMENT}" -m ${USER_NAME}
read -p "Please Enter Your Password: " PASSWORD
echo -e "$PASSWORD\n$PASSWORD" |passwd "$USER_NAME"
passwd -e ${USER_NAME}
答案 1 :(得分:0)
在 Debian 10 @ Docker 镜像上测试
echo -e "badpass\nbadpass" | passwd urname
这适用于 /bin/bash,而不适用于 /bin/sh
echo "urname:badpass" | chpasswd
这将适用于 /bin/sh 和 /bin/bash