I'm using a MacOS. I tried to enter this environment variable inside my .bash_profile:

export CLOUD_PASSWORD=Pass4Aa$ditya

But when I do source .bash_profile and try echo $CLOUD_PASSWORD, I get this as output: Pass4Aa

Anything after that $ sign is getting ignored. Even when I tried adding quotes like: export CLOUD_PASSWORD="Pass4Aa$ditya"

and did source later, it is still showing the same as before. How do I create environment variables with Special Characters like $ and @ present in the value?

$ export CLOUD_PASSWORD='Pass4Aa$ditya'
$ printf '%s\n' "$CLOUD_PASSWORD"


$ export CLOUD_PASSWORD="Pass4Aa\$ditya"
$ printf '%s\n' "$CLOUD_PASSWORD"


single quotes or escaping with backslashes :)


Use single quotes to assign value to variable in .bash_profile file.

Add following line in .bash_profile -

export CLOUD_PASSWORD='Pass4Aa$ditya'

Verify the changes -

$ source .bash_profile
$ printf '%s\n' "$CLOUD_PASSWORD"

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