Knowledgebase

Environment Variables and the Shell Environment Print

  • 0

How the shell knows things.

WHAT AN ENVIRONMENT VARIABLE IS

A value available to programs the shell starts.

WHAT THE IMPORTANT ONES ARE

The search path The home directory The current user The shell The language and character set

WHAT THE PATH DETERMINES

Which directories are searched for commands, in order.

WHY IT EXPLAINS ODD BEHAVIOUR

The wrong version of a program runs because it appears earlier.

HOW TO SEE WHICH WILL RUN

Use which or command with the v option.

WHAT export DOES

Makes a variable available to programs the shell starts.

WHY IT MATTERS

Without it, the variable exists only in the shell itself.

WHERE SETTINGS PERSIST

Shell startup files in the home directory.

WHAT THE DIFFERENCE BETWEEN LOGIN AND NON-LOGIN SHELLS IS

Which files are read.

WHY IT CAUSES CONFUSION

A setting that works interactively is absent in cron or scripts.

WHAT TO DO IN SCRIPTS

Set what you need explicitly, rather than relying on inheritance.

WHAT TO NEVER PUT IN ENVIRONMENT FILES

Secrets committed to version control.

WHAT TO CHECK WHEN A COMMAND BEHAVES DIFFERENTLY IN CRON

The path, and the environment generally.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot