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?

Sparker0i
  • 161

2 Answers2

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
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
kishs1991
  • 131
  • 2