试图将用户输入从我的Bash脚本输出到一个txt文件



我对Shell脚本世界还很陌生,但我已经编写了这个简单的Bash脚本,它将接收用户帐户注册信息,我需要将其输出到稍后使用的文本文件中。我尝试了各种方法,但似乎都无法使用。如果能在这方面提供任何帮助,我们将不胜感激。

这是我迄今为止写的代码

#!/bin/bash
clear
echo "Welcome, This Is The Registration Form Associated With Option 1"
echo "--------------------------------------------"
echo "Please enter In the Requsted Details Below"
echo -e "-------------------------------------------- n"
#Taking in the users Registration Information
echo "Please Enter Your Full name (Forename and Surname): "
read AccountName
echo "Please Enter Your Date of Birth in the format (DD/MM/YYY): "
read DOB
echo "Please Enter The Username You Would Like To Have While Using The System: "
read Username
echo "Please Enter The Password You Want To Associate With This Account: "
read -s Password
echo "Please Enter The Email Address You Want To Associate With This Account: "
read Email
#Redirecting The Users Account Registration Information to a text file called Register.txt
# Output infromation above to a text file?? 

只需将输出重定向到文件:

#!/bin/bash
...
# Redirect all further output to Register.txt
exec >> Register.txt  # This will append to the file: probably you want
# additional logic to handle existing records
printf "Accountname: %sn" "$AccountName"
printf "DOB: %sn" "$DOB"
...

您可以将stdout重定向到具有>:的文件

printf "%sn" "$AccountName" "$DOB" "$Username" "$Password" "$Email" > Register.txt

相关内容

  • 没有找到相关文章

最新更新