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!

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

env VAR=panda ./myprogram

This sets VAR to panda in myprogram’s environment (but not in the current shell).

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 2021 | All rights reserved (see the FAQ for notes about licensing)