直到用户输入等于做的东西 [英] Until user input equals something do
问题描述
所以,有人向我展示了如何使用条件(S)来测试,如果用户输入了输入密码。
我想坐他们的榜样了一步,使用循环(至少我是这么认为它是调用)。
So somebody showed me how to use condition(s) to test if a user had typed input for a password. I wanna take a their example a step further and use a loop (at least thats what I think it's call).
下面是他们的例子:
read -s -p "Enter new password: " NEWPASS
if test "$NEWPASS" = ""; then
echo "Password CAN NOT be blank re-run sshd_config"
exit 1;
fi
不是退出,我希望它继续要求输入脚本,直到有一些。
Instead of exiting the script I want it to keep asking for the input until there is some.
我要让这样的说法,但我做错了:
(现在使用顶部的例子)
I wanna make a statement like this but I was doing it wrong: (Now using top example)
该用户有机会输入新的密码,并填写变量值。
The user is given a chance to enter new password and fill the variable value.
read -s -p "Enter new password:" NEWPASS
echo ""
接下来部检查变量,看看它是否包含一个值,而值为空它要求用户无限制地填补的值。 (一环)
The next portion checks the variable to see if it contains a value, while the value is null it request the user to fill the value indefinitely. ( a loop)
while [[ -z "$NEWPASS" ]]; do
echo ""
echo "Password CAN NOT be blank"
echo ""
read -s -p "Enter new password:" NEWPASS;
echo ""
done
这行搜索含有一组由另一个文件使用的变量的文件。然后查找该文件包含PASS =行。*(*意味着什么)然后写入PASS = $ NEWPASS($ NEWPASS是可变的)
This line searches a file containing a set of variables used by another file. It then searches the file for a line containing PASS=.* (.* meaning anything) then writes PASS=$NEWPASS ($NEWPASS being variable)
sed -i -e"s/^PASS=.*/PASS=$NEWPASS/" /etc/sshd.conf
感谢您的所有帮助,我会用这个,并从中吸取教训。
Thank you for all the help, I'm going to use this and learn from it.
推荐答案
这while循环应该工作:
This while loop should work:
while [[ -z "$NEWPASS" ]]
do
read -s -p "Enter new password: " NEWPASS
done
这篇关于直到用户输入等于做的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!