Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.4k
  • 205
  • 1.8k
  • 2.3k
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link
P.Brian.Mackey
  • 2k
  • 4
  • 18
  • 20

Basic syntax explanation for variables in bashrc

I want to correctly export a variable. In order to do so I have to understand several variations in syntax. I've seen the following mechanisms of exporting a variable. In this case I am using .bashrc:

  1. export MY_VARIABLE=$USER/.gradle --$

  2. export MY_VARIABLE="$USER/.gradle" --Quotes

  3. export MY_VARIABLE=USER/.gradle --No $

  4. export $MY_VARIABLE=$USER/.gradle --All the $

What is the significance of the $ sign in these cases? Why is it sometimes used and other times not?

Do we need quotes in cases where there are no spaces in the path? What if the path is contained in $USER contains spaces?

Why no $ on the left hand side of export?