You set a value in your terminal, start a program, and the program behaves as though the value does not exist. The missing step may be how that setting reaches the program.
Linux environment variables are named values supplied to a program when it starts. Programs can use them to find commands, choose language settings, or receive application-specific configuration.
This lesson explains the difference between a value stored in your shell and a value passed to another program. You will observe that boundary without editing configuration files or restarting services.
A shell variable belongs to the shell that holds it. Marking it with export makes it available in the environment of commands the shell subsequently launches.
That environment is passed onward at startup. It is not a shared settings panel that automatically updates every running program.
- How shell variables differ from exported variables.
- How to inspect a value without printing your entire environment.
- Why PATH affects command lookup.
- Why changing a terminal setting does not reconfigure an existing service.
- 🧠 Start with the Shell and the Program
- Shell Variables and Environment Variables
- 🔍 Inspect One Setting at a Time
- How PATH Helps the Shell Find Commands
- 🧪 Mini Lab: Follow a Value into a Child Process
- 1. Open a Practice Shell
- 2. Store a Value and Read It in the Shell
- 3. Ask an External Program to Read It
- 4. Export and Repeat
- 5. Override One Launch
- 6. Leave the Practice Shell
- Why Changing a Variable Does Not Update Everything
- Why a Service Can Have Different Settings
- Does export Make a Setting Permanent?
- ⚠️ Common Mistakes
🧠 Start with the Shell and the Program
The shell is the program that interprets commands you type. Bash is one common shell on Linux. A terminal provides the interface; the shell decides what your command means.
When the shell launches another program, that program runs as a process: an executing instance of a program. The process that starts it is its parent, and the newly started process is its child.
A variable such as SA_LESSON_MODE=practice contains a name and a text value. The name alone has no special power. A real application must be written to read that name and interpret its value.
For example, inventing FAST_MODE=yes does not make arbitrary software faster. Configuration works only when the program recognizes the setting.
Shell Variables and Environment Variables
Assigning a value gives the shell something to remember. Exporting marks that value for inclusion when the shell launches commands.
| Form | What it does | Scope |
|---|---|---|
| Shell variable | Stores a value the shell can use | The current shell; not automatically exported |
| Exported variable | Includes the value in launched commands’ environments | The shell and commands it subsequently launches |
| Assignment before an external command | Supplies a value for that command | That launch, without replacing the parent shell’s value |
There is one useful detail: variables Bash inherits from its own environment are already marked for export. Assigning a new value to one does not remove that marking.
For the exact inheritance rules, see the Bash environment documentation.
🔍 Inspect One Setting at a Time
To ask what PATH value a newly launched command receives, run:
printenv PATH
printenv prints the named variable from its own environment. Because your shell launched it, this is a useful check of what the shell passes onward.
An illustrative result is:
/usr/local/bin:/usr/bin:/bin
Your directories may differ. Focus on the colon-separated entries rather than expecting this exact output.
This command does not inspect a web server that is already running. It also does not list variables held only inside your shell. The GNU printenv documentation describes its output and return codes.
Running printenv without a name prints the whole environment. It may contain credentials or private configuration. For learning and troubleshooting, request the specific non-sensitive setting you need.
How PATH Helps the Shell Find Commands
Typing ls does not tell the shell where the executable file is located. For an external command named without a slash, PATH supplies directories to search in order.
With the example above, the search begins in /usr/local/bin, then checks /usr/bin, then /bin. PATH contains directories, not a list of individual executable files.
Bash also has commands implemented inside the shell, called builtins, and supports functions. Those can be selected before an external executable search. Bash can remember previously resolved executable locations, too.
A command containing a slash supplies a path directly. For example, ./report refers to a file named report in the current directory. It does not request the usual PATH search.
Finding an executable is only the first step. The file still needs to be runnable, and its application configuration must still be valid. The Bash command lookup reference explains this distinction.
🧪 Mini Lab: Follow a Value into a Child Process
Use a Linux terminal with Bash and printenv available. The exercise changes only temporary variables in a practice shell. It creates no files, requires no administrator privileges, and does not change services or PATH.
Enter each step separately so you can interpret its result before continuing.
1. Open a Practice Shell
Start a nested Bash session that skips its usual interactive startup files. Your original shell remains underneath it.
bash --noprofile --norc
The prompt may change. This shell still inherits an environment; skipping startup files does not mean starting with no variables.
Clear our demonstration name inside this practice shell so an inherited value cannot affect the exercise:
unset SA_LESSON_MODE
There is normally no output. This removes only the named variable from the practice shell.
2. Store a Value and Read It in the Shell
Create a variable, then ask the shell to insert its value into a printed line:
SA_LESSON_MODE=practice
printf '%s\n' "$SA_LESSON_MODE"
Expected output:
practice
Keep the assignment together: there are no spaces around =. The $ requests the variable’s value. Double quotes keep that expansion together as one argument, including when a value contains spaces.
printf uses %s to print the supplied text and \n to finish the line. This proves the shell can read the value; it does not prove the value was exported.
3. Ask an External Program to Read It
Now launch a separate program and ask it for the same variable:
printenv SA_LESSON_MODE
Expect no output. The variable exists in the shell, but this newly launched program did not receive it.
GNU printenv also returns status 1 when a requested variable is missing. A return status is a small result code a command leaves for its caller. Here, that result is expected evidence—not a broken installation.
4. Export and Repeat
Mark the existing variable for export, then launch a fresh reader:
export SA_LESSON_MODE
printenv SA_LESSON_MODE
Expected output:
practice
The comparison is the lesson: the first reader received no value; the second received one after you changed the export marking.
5. Override One Launch
Supply a different value to one external command, then launch another reader normally:
SA_LESSON_MODE=inspection printenv SA_LESSON_MODE
printenv SA_LESSON_MODE
Expected output:
inspection
practice
The first launch used its temporary override. The next launch received the practice shell’s existing value.
6. Leave the Practice Shell
Return to your original shell:
exit
The practice shell ends. Its variable changes do not flow back into the shell that started it. Run this once to leave the nested session.
Why Changing a Variable Does Not Update Everything
Environment inheritance has a direction. A parent supplies values when starting a child; the child can then maintain its own values.
Imagine two application processes started with a label of practice. Changing the launching shell’s label afterward does not rewrite either application’s environment. A third application launched later can receive the new value.
Similarly, a child cannot update its parent’s environment just by changing its own variables. This separation explains why the lab’s settings disappeared when you returned to the original shell.
When a setting appears to be missing, ask two questions: which process needed it, and which process launched that process? Checking a convenient terminal is useful only when it represents the relevant launch context.
The Bash execution environment reference describes this separation.
Why a Service Can Have Different Settings
A system service is normally started by the service manager, not by your interactive terminal. It therefore does not automatically receive variables you just exported in that terminal.
The existing lesson on creating a systemd service introduces explicit environment configuration. That configuration belongs to the service’s launch context.
Before changing a service, identify which setting the application actually requires and how its launcher supplies that setting. A successful terminal experiment proves the terminal case; it does not establish what the service received.
Scheduled tasks have the same environment boundary. Cron does not simply replay your interactive shell, so variables and command paths that work in a terminal may be missing when a scheduled command runs. See the Linux cron jobs guide for crontab schedules, execution environments, output handling, and troubleshooting.
Does export Make a Setting Permanent?
No. Export controls inheritance, not storage on disk.
Future shells can recreate settings by reading startup files. Which files Bash reads depends on how it starts. An interactive non-login Bash normally reads ~/.bashrc; a login Bash follows a different startup sequence.
A shell running a script also has different rules. Consequently, putting a line into one startup file does not make it universal application configuration.
This lesson deliberately avoids editing those files. First understand the scope you need: one command, one terminal session, future interactive shells, or a managed service. Then use the configuration mechanism appropriate to that scope.
Consult Bash startup file rules before making a persistent shell change.
⚠️ Common Mistakes
Reading a shell variable and passing it to another program are different operations. The lab checks both sides separately.
Export affects subsequent launches from that shell. An existing process does not receive a live stream of your terminal changes.
The shell may simply be unable to find it through its current lookup rules. Investigate the expected executable location before reinstalling software.
A named setting can exist with an empty text value. Applications may distinguish that from a setting that was never supplied. Check the application’s documented behavior.
- Your shell prints a new variable, but printenv cannot find it. What is the likely missing step?
- A variable assignment before one printenv command produces a different value. Why does the next command still see the old value?
- You export a setting after an application has started. Should that application automatically receive it?
- What information does PATH contain, and why can two terminals find different executable files?
- Why does a successful terminal test not prove that a system service has the same environment?
- Does export save a setting for your next login?
🎓 Check Your Answers
- The new variable probably has not been marked for export. The shell can use its own value even when it does not include that value in an external command’s environment.
- The assignment applied to that external command’s launch. It did not replace the parent shell’s stored value, so a later launch received the original value.
- No. Changing the shell’s export settings does not rewrite an existing application’s environment. Follow the application’s configuration procedure when an update is required.
- PATH contains an ordered list of directories for executable lookup. Different lists or ordering can lead to different executable selections.
- The service has a different launcher. A service manager does not automatically use the settings exported in your interactive terminal.
- No. Export is an inheritance instruction. Persistent configuration requires an appropriate startup or application configuration mechanism.
Follow a setting from the place it is defined to the process that needs it. Its presence in your terminal is only one part of that journey.
When behavior differs between a terminal, a script, and a service, compare how each program was launched and which settings it received. That gives you a concrete question to investigate before changing the system.








