shell小技巧(四十)编写一个修改用户密码的脚本

脚本提示输入用户名,和密码。如果用户存在则提示用户输入密码(密码要求重复输入2次一致密码)

#!/bin/bash
flag=1
while [ $flag -eq 1 ];do
read -p "please input name:" Tusername
ckusername=$(grep "${Tusername}:" /etc/passwd | wc -l)
if [ $ckusername -eq 0 ]; then
   echo $Tusername " was not found!"
else
   break;
fi
done

while  [ $flag -eq 1 ];do
   read -s -p "please input password:" p1
   read -s -p "please input password again:" p2
   if [ $p1 == $p2 ];then
      break;
   else
      echo "first input and sencond input are not same"
   fi
done
echo $p1 | passwd allenle --stdin
总结:

一个passwd接受标准输入修改密码的技巧

另外就是read输入和while循环的使用,这个之前的例子出现过

发布了95 篇原创文章 · 获赞 3 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/bigwood99/article/details/105354637