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


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

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

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.


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

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.


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.