Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, Bite Size Bash!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

panel 1: every process has environment variables

how to see any process’s environment variables on Linux:

cat /proc/$PID/environ | tr '\0' '\n'

panel 2: shell scripts have 2 kinds of variables

  1. environment variables
  2. shell variables

unlike in most languages, in shell you access both of these in the exact same way: $VARIABLE

panel 3: export sets environment variables

export ANIMAL=panda

export ANIMAL=panda means that every child process will have ANIMAL set to panda

panel 4: child processes inherit environment variables

this is wy the variables set in your .bash_profile work in all programs you start from the terminal. They’re all child processes of your bash shell!

panel 5: shell variables aren’t inherited

var=panda

in this example, $var only gets set in this process, not in child processes

panel 6: you can set environment variables when starting a program

Illustration of a smiling stick figure with curly hair, talking to env, represented by a box with a smiley face.

Person: env VAR=panda ./myprogram
env: OK! I’ll set VAR to panda and then start ./myprogram

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)