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")
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
$ 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.
The OP ended up using this method to prompt the user for their password using
read and then storing it in a variable,
$ read -p "Password: " -s pass1
This variable could then be used as input to the
$ myvar=$(openssl passwd -1 -salt "foobar" -stdin <<< "$pass1") $ echo $myvar $1$foobar$1ips4/cyJvjUjCj8w4exx0