I am trying to generate a hashed password as in /etc/shadow
file, using bash script. The user is prompted for the password which is saved in a variable PSWD
. I have extracted the Hash and the salt value from the /etc/shadow
file and saved them in a variables HVAL
and SVAL
respectively.
Now in order to generate a hashed password using Password and the Salt value, I need to use command given below (Reference):
$ perl -e 'print crypt("password","\$6\$salt\$") . "\n"'
In the above command, I must replace "password" with the $PSWD
variable, "6" with $HVAL
and "salt" with $SVAL
variable.
I've tried exporting above variables and replacing them in the perl command, as shown below, but it was totally messed up.
perl -e 'print crypt("$ENV{"PSWD"}","\$$ENV{"HVAL"}\$$ENV{"SVAL"}\$") . "\n"'
What will be the corrections?
"$ENV{\"VAR\"}"
though"$ENV{VAR}"
would be enough, see my answer.