I am generating a password hash that I would like to base on user input for use later in the script. I have tried variations on the syntax for the bash variable in the following:
#!/bin/bash
printf "Enter password:"
read pw
php -r 'echo password_hash("$pw", PASSWORD_DEFAULT, [ "cost" => 11 ]) . "\n";'
I get the correct hash but only after I get an undefined variable warning.
When I put the variable in single quotes '$pw' and then input the password as "password" or 'password' I do not receive the error.
How can I pass a bash variable to a php command or otherwise assign it to a php variable within a bash script without the undefined variable error message?