

We can also verify this behavior this using a non-shell language such as Python: WOOKIE= "Chewbacca" The same rules apply to scripts, for example, if a file shell-var-test.sh contained the following: # shell-var-test.sh echo "The Wookie's name is $WOOKIE"Īnd shell-var-test.sh was run even after NAME was defined, it's not accessible to the script. # In a new shell echo "The Wookie's name is $WOOKIE" # > The Wookie's name is If you opened a new shell and ran the echo command, the NAME variable does not exist as it was scoped to the previous shell only. WOOKIE= "Chewbacca" echo "The Wookie's name is $WOOKIE" # > The Wookie's name is Chewbacca # Shell variable as it does not use the `export` command Shell variables should be used when they are only needed in the current shell or script in which they were defined. Simplistically, shell variables are local in scope whereas environment variables are global, but let's explore this further with examples. Difference between shell and environment variables

That's only the tip of the iceberg, so let's dive deeper. # Quotes recommendedĮxport FULL_NAME= "Darth Vader" # Getting an environment variable's value # Note the $ prefix used for referencing echo "Anakin Skywalker is now $FULL_NAME" # > Anakin Skywalker is now Darth Vader Let's look at the basics for setting and accessing environment variables using the following commands: # Setting an environment variable # The `export` keywords essentially means "make this globally accessible" # No spaces on either side of the equals sign. The values of environment variables can control the behavior of an operating system, individual utilities such as Git, shell scripts, user applications such as the Google Chrome browser, or deployed applications such as a Python web app.
#Editing path in mac .bash_profile for multiple items how to
