我正在编写Windows共享的安装脚本,以便在登录后运行。我已经用bash和zenity做到了,它可以工作,但是现在我需要做得更好,因此,如果用户名字段和密码字段为空,则返回到输入。
例子
wUsername=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Kasutajanimi:"`
#if [ $? -ne 0 ]; then
# exit 1
#fi
if [ -z "$wUsername" ]; then
zenity --error --title="Viga kasutajanimes!" --text="Palun sisestage oma kasutajanimi"
# get the windows password
wPassword=`zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Parool:" --hide-text`
if [ $? -ne 0 ]; then
exit 1
fi
因此,如果Kasutajanimi aka用户名或Parool aka密码为空,我希望此脚本将用户拉回输入。即使按下空格。
我已经在所有功能强大的Google上进行了搜索,并且知道以某种方式可以退货。
我会这样:
#!/usr/bin/env bash
## Define a function that launches the zenity username dialog
get_username(){
zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Kasutajanimi:"
}
## Define a function that launches the zenity password dialog
get_password(){
zenity --entry --width=300 --title="Mount $MOUNTDIR" --text="Parool:" --hide-text
}
## Attempt to get the username and exit if cancel was pressed.
wUsername=$(get_username) || exit
## If the username is empty or matches only whitespace.
## See http://www.tldp.org/LDP/abs/html/string-manipulation.html
## for an explanation of this syntax. The . means any non-space
## character so when this is less than 1, the username is empty
## or just whitespace. Since this is a while loop, the process
## will be repeated until the username is correctly submitted.
while [ "$(expr match "$wUsername" '.')" -lt "1" ]; do
zenity --error --title="Viga kasutajanimes!" --text="Palun sisestage oma kasutajanimi"
wUsername=$(get_username) || exit
done
## Same as the previous loop but for the password. Sorry if
## the message is wrong, I don't speak this language :)
wPassword=$(get_password) || exit
while [ "$(expr match "$wPassword" '.')" -lt "1" ]; do
zenity --error --title="Viga Parool!" --text="Palun sisestage oma Parool"
wPassword=$(get_password) || exit
done
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句