Setting Variables
Learn to create your own variables with export and understand the difference between shell and environment variables.
GREETING=hello. No spaces around the = sign — this is a common mistake. To promote it to a full environment variable (so child processes can see it), use export: export GREETING=hello. Once set, you reference it with $GREETING.export MY_NAME="terminal learner"
echo $MY_NAMEexport line to a configuration file like ~/.bashrc or ~/.zshrc — but that's a topic for a later module.Remember: no spaces around the equals sign. MY_VAR="hello" works. MY_VAR = "hello" does not — the shell thinks you're trying to run a command called MY_VAR with arguments = and hello.
Be careful not to overwrite important system variables like PATH or HOME. If you accidentally clear PATH, your shell won't be able to find any commands until you fix it or open a new terminal.
In PowerShell, you set variables with $MyVar = "value" (spaces are fine). To set a persistent environment variable, use [Environment]::SetEnvironmentVariable("MY_VAR", "value", "User"). In Command Prompt, use set MY_VAR=value for the session or setx MY_VAR value for persistence.
export to create a variable, then use echo with a $ prefix to read it back.export FAVORITE_COLOR="blue"
echo $FAVORITE_COLOR