3
我有一个程序,询问用户输入他们的用户名和密码,然后将其存储在文本文件列一个是用户名和第2列是密码,我需要一个命令,以取代密码时用户输入自己的用户名和新密码,继承人我有什么用户名,密码程序在bash
#!/bin/bash
#admin menu
#Register User
echo enter the username of the user you want to register.
read reguser
echo enter the password of the user you want to register.
read regpass
User_Pass="username_pass.txt"
if [ ! -e "$User_Pass" ];
then
echo "Creating Username and Passwords file"
touch $User_Pass
fi
echo "$reguser $regpass" | cat >> $User_Pass
echo user succesfully registered.
#Change Password
echo "Enter the username you want to change the password for"
read change1
change2=$(grep -q $change1 username_pass.txt)
if [ $change2=0 ];
then
echo enter your new password
read newpass
awk -v newpass="$newpass" -v change1="$change1" '$1 ~ change1 {$2 = newpass}' username_pass.txt
#i tried this but it didnt work
echo "password changed!"
else
echo "no such username."
fi
请看看:http://www.shellcheck.net/ – Cyrus