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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Sparker0i
  • 161
  • 1
  • 1
  • 5

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 :)

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
yhoogstrate
  • 324
  • 2
  • 3
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
  • 66,199
  • 35
  • 114
  • 250
kishs1991
  • 131
  • 2