我一直在四处寻找但无法找到解决方案......
基本上,我有一个创建用户帐户的程序,我也可以使用命令行界面创建一个帐户 我想要的是,当我使用命令行时,程序的其余部分都不会运行。因为此时它会创建帐户,然后返回菜单。
function menu {
echo "Welcome to OP-SYS Account creation. Please choose which mode you would like to continue in."
echo
echo "[1] Basic Account Creation"
echo "[2] Advanced Account Creation"
echo "[3] Exit"
echo
#Change user input to functions, reject others
read CHOICE #Load user input to variable
if [ "$CHOICE" = 1 ] || [ "$CHOICE" = 2 ] || [ "$CHOICE" = 3 ]; then
#Goto function opt#
opt"$CHOICE"
else
echo "That is not a valid entry. Returning you to the menu."
sleep 2
clear
menu
fi
}
#other code#
konsoleend() {
clear
#popd
}
username=$1
firstname=$2
surname=$3
password=$4
echo "$firstname" "$surname" >> "$username".log
echo "$password" >> "$username".log
curdate=$(date +'%d/%m/%Y %H:%M:%S')
echo "$curdate" >> "$username".log
#menu
konsoleend
menu
答案 0 :(得分:1)
它完全不清楚你的意思是什么 "命令行界面"和#34;程序",但也许你只是意味着如果没有给你想要使用菜单的程序的参数。如果是这种情况,只需写下:
test $# = 0 && menu
在脚本的最后一行,而不仅仅是menu