Skip to Content

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!

how to set a variable

  • var=value right (no spaces!)
  • var = value wrong

var = value will try to run the program var with the arguments “=” and “value

how to use a variable: “$var”

echo "$filename"

they’re case sensitive. environment variables are traditionally all-caps, like $HOME

there are no numbers, only strings


both of these are the string “2”

technically bash can do arithmetic, but I avoid it

always use quotes around variables

$filename="swan 1.txt"

$ cat $filename (wrong)

bash: ok, I’ll run cat swan 1.txt
2 files! oh no! we didn’t mean that!
cat: Um swan and 1.txt don’t exist…

$ cat “$filename” (right!)

bash: ok, I’ll run cat "swan 1.txt"
cat ‘“swan 1.txt”`! that’s a file! yay!


To add a suffix to a variable like “2”, you have to use ${varname}. Here’s why:

$ zoo=panda
$ echo "$zoo2" prints "", zoo2 isn’t a variable
$ echo "${zoo}2" this prints “panda2” like we wanted

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)