1

How would I be able to catch the input for a substituted command stored in a variable?

Example:

How would I be able to catch the input for the following command?

bar_foo=$(openssl passwd -1 -salt "foobar")

1 Answer 1

1

The approach you're showing above would catch the output from the subcommand, ie. $(...) into your variable, $bar_foo. When using openssl you can provide the password using either the -in or the -stdin switches.

Example

$ myvar=$(openssl passwd -1 -salt "foobar" -stdin <<< "blah")
$ echo $myvar
$1$foobar$1ips4/cyJvjUjCj8w4exx0

It's generally advisable to put the password in a file and then call openssl, since that'll keep it out of your history and shield it from being exposed too openly.

UPDATE #1

The OP ended up using this method to prompt the user for their password using read and then storing it in a variable, pass1.

$ read -p "Password: " -s pass1

This variable could then be used as input to the openssl command.

$ myvar=$(openssl passwd -1 -salt "foobar" -stdin <<< "$pass1")
$ echo $myvar
$1$foobar$1ips4/cyJvjUjCj8w4exx0
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.