从uni那里重新学习bash,并制作一个密码生成器。我希望能够将结果输出到文本文件,任何人都可以帮忙吗?到目前为止,我的代码是:
#!/bin/bash
#Password Generator
#Account Name
echo "What account is this password for"
read account
#username
echo "Please give your username"
read username
#ask for password length
echo "please provide a password length"
read length
echo "Your password is"
openssl rand -base64 $length
我希望能够从帐户,用户名以及文本文件的密码输出结果,在此先感谢您的帮助,我希望此查询有意义!
有多种方法可以执行此操作,但最终只有两种方法:管道传输到文件或管道传输到写入文件的程序。
我在下面创建了一些修改后的脚本版本,展示了一些方法。
#!/bin/bash
#Password Generator A 1.1
#A random password generator written for Bash.
#Dependencies: Gedit, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to new file in Gedit
echo "$output" | gedit -
exit 0
#!/bin/bash
#Password Generator B 1.1
#A random password generator written for Bash.
#Dependencies: Nano, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to new file in Nano
echo "$output" | nano -
exit 0
#!/bin/bash
#Password Generator C 1.1
#A random password generator written for Bash.
#Dependencies: OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to file
echo "$output" > "$HOME/output"
exit 0
#!/bin/bash
#Password Generator D 1.1
#A random password generator written for Bash.
#Dependencies: Tee, OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
##Generate Password
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal & file
echo "$output" | tee "$HOME/output"
exit 0
#!/bin/bash
#Password Generator E 1.1
#A random password generator written for Bash.
#Dependencies: OpenSSL
##Request Inputs
###Account Name
echo -n "Account Name:"
read account
###Username
echo -n "Username:"
read username
###Password Length
echo -n "Password length:"
read length
###Save Location
echo -n "Save to:"
read savelocation
##Generate Password
password=$(openssl rand -base64 $length)
##Generate Result
###Merge variables
output=$(echo -e "Account Name:${account}\nUsername:${username}\nPassword:${password}")
##Output result
###Output to terminal
echo "$output"
###Output to file
echo "$output" > "$savelocation"
exit 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句