💾 Archived View for yujiri.xyz › software › guide › env.gmi captured on 2023-06-16 at 16:55:30. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

yujiri.xyz

Software

Learn programming for good instead of profit

Process environment

On Unix-like operating systems, a process has an *environment*, which is a set of keys and corresponding values. Normally, when a process starts, it inherits the environment of the process that created it (its "parent process"). For example when you start a program from your shell, it inherits your shell's environment. So, what kind of things are in your shell's environment?

One of them is HOME, which is set to the absolute path to your home folder. (They are usually named in all caps.) You can see it by running `echo $HOME`. If you haven't seen it already, `echo` is a shell command that just prints whatever text you give it to stdout, and the $ symbol tells your shell that `HOME` is not literal text but the name of an environment variable. So, any program you start from the shell can find out what your home folder is by reading this variable from its environment.

Another one is PATH, which is a list of folder paths, separated by colons, that commands are installed in. When you type a command like `ls`, your shell looks at the PATH variable in its environment, and tries to find the `ls` binary inside one of those folders. Try `echo $PATH`. You'll probably see something like `/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin`. Also, feel free to `ls` any of those folders to see which commands they contain.

Your environment probably has a bunch of other, relatively obscure things in it. You can see all of them with the command `env`.

Now, compare four different ways a process can take input: arguments, environment, stdin, and configuration files. Consider what each is best used for.

arguments:

environment:

stdin:

configuration files:

contact

subscribe via RSS