【发布时间】:2015-07-20 16:15:21
【问题描述】:
我正在尝试了解如何使用命令行在我的程序中输入不超过三个参数...
它当前要求用户说出他们的用户名、名称和密码——然后将名称、密码和创建日期/时间放入日志文件中,用户名作为 doc 文件——如下所示
function savefile {
# Save to file
if [ -e "$username".log ]; then
echo "Username already exists, returning you to the menu."
sleep 2
clear
menu
else
echo "$fullname" >> "$username".log
echo "$password" >> "$username".log
curdate=$(date +'%d/%m/%Y %H:%M:%S')
echo "$curdate" >> "$username".log
echo "Creating your account"
sleep 2
clear
echo "Account created"
echo
afterBasic
fi
}
想知道你们是否知道如何从命令行执行此操作?我知道我必须使用
sh 1 2 3
但仅此而已……
这是用 Batch 编写的相同内容,如果这也有帮助的话......
set OP_username=%1
set OP_fullname=%2
set OP_password=%3
if [%3]==[%9] goto 1
echo %OP_fullname% >> %OP_username%.log
echo %OP_password% >> %OP_username%.log
echo %date% %time% >> %OP_username%.log
【问题讨论】:
标签: linux bash batch-file command-line