How can you create a new environment variable?

QuestionsQuestions4 SkillsProDec, 21 2025
0178

To create a new environment variable in Linux, you use the export command. Here is the simplest way to do it:

1. Temporary Variable (Current Session)

To create a variable that lasts as long as your current terminal window is open, use this format:

export MY_VARIABLE="Hello LabEx"

You can then verify it was created by using echo:

echo $MY_VARIABLE

2. Standard Variable (No Export)

If you simply type NEW_VAR="Value", it becomes a shell variable. It works in your current shell, but it won't be passed to any programs or scripts you run from that shell. Using export ensures that it becomes an environment variable available to child processes.

Key Rules:

  • No spaces: Do not put spaces around the = sign (e.g., VAR = "value" will cause an error).
  • Case Sensitivity: By convention, environment variables are usually written in UPPERCASE to distinguish them from regular file names or commands.
  • Quotes: Use quotes if your value contains spaces (e.g., NAME="John Doe").

Try it now: Try running export COURSE="Linux Basics" and then echo $COURSE in your terminal

0 Comments

no data
Be the first to share your comment!