

WOOKIE="Chewbacca"Įnvironment variables, on the other hand, are designed to be accessible to scripts or child processes and differ from shell variables by use of the export command. The same rules apply to scripts, for example, if a file shell-var-test.sh contained the following: # shell-var-test.shĪnd shell-var-test.sh was run even after NAME was defined, it's not accessible to the script. 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. # 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. # Getting an environment variable's valueĮcho "Anakin Skywalker is now $FULL_NAME" # No spaces on either side of the equals sign.

# The `export` keywords essentially means "make this globally accessible" Let's look at the basics for setting and accessing environment variables using the following commands: # Setting an environment variable 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.
