переучил 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
Я хотел бы иметь возможность выводить результаты из учетной записи, имя пользователя и пароль в текстовый файл Заранее благодарен за любую помощь, и я надеюсь, что это запрос имеет смысл!
Существует несколько способов сделать это, но в конечном счете только 2 подхода: передайте по каналу в файл или канал к программе, которая пишет в файл.
я создал некоторые измененные версии Ваших сценариев ниже, демонстрируя некоторые методы.
#!/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
Можно перенаправить любой вывод с эхом как: cmd> имя файла или в Вашем случае:
openssl rand -base64 $length > passwords.txt