Calling programs with environment variables

Environment variables are properties of all processes, not just bash processes. They can be read by other programming languages, such as C, Perl, Awk, or Python. This means that environment variables are sometimes used to affect how another program runs.

For example, the sort program uses locale settings to decide the sort order for some strings  specifically, it uses the LANG or LC_COLLATE environment variables. If LC_COLLATE is set to en_US.UTF-8, it will sort lowercase a before uppercase A:

$ printf '%s\n' 'alligator' 'Alfred' >words
$ LC_COLLATE=en_US.UTF-8
$ export LC_COLLATE
$ sort words
alligator
Alfred

However, if the environment variable is then set to C, its behavior changes:

$ LC_COLLATE=C ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.