5

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?

2

2 Answers 2

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

Pass4Aa$ditya

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

Pass4Aa$ditya

single quotes or escaping with backslashes :)

3

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"
Pass4Aa$ditya

Not the answer you're looking for? Browse other questions tagged .