I am working on PGP encryption. I am getting public keys from some file.
One of the key has dollar sign in it "$" Example: "abc$123"
echo 'passphrase='$passphrase --> Giving correct value abc$123
But if I use $passphrase in PGP command getting Invalid passphrase error.
If I hardcode "abc$123" encryption is working fine.
Getting error only if I am referring $passphrase in PGP command.
Please help how to handle $ sign in shell script variable
I can't tell why code I can't see isn't working. Please show your code.
I doubt that the dollar sign causes the problem, though. Shell is quite careful not to interpret dollar signs in strings as variables -- only in the shell's code itself is the value special.
Variables inside single quotes don't work, variables inside double quotes are expanded. This might be the issue.
If you don't set passphrase to anything, $passphrase will not work.
If you did set passphrase to something, there may be something wrong with the way you did it. I can't tell because you didn't show that code. Show all your code.
You should probably quote it, too, "$passphrase", to prevent the shell from splitting it on spaces etc.
What we want to say is that --passphrase "abc$123" does NOT work as intended because it expands to --passphrase "abc${1}23" and if $1 is empty expands to --passphrase "abc23" .
But
If your code - whatever it is - is evaluating dollar signs in passwords, that's a big problem. What if someone set their password to $(rm -Rf /var/importantdata) ?
Please show your code so we can find out why it's doing that.