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!

panel 1: ${...} is really powerful

person: “it can do a lot of string operations, my favourite is search/replace

panel 2: ${var}

same as $var

panel 3: ${#var}

length of the string or array var


$ x=panda
$ echo ${#x}

panel 4: ${var/bear/panda}

search & replace. Example:

$ x="I'm a bearbear!
$ echo ${x/bear/panda} # replace 1 instance of 'bear'
I'm a pandabear!
$ echo ${x//bear/panda} # replace every instance of 'bear'
I'm a pandapanda!

panel 5: ${var:-othervar}

use a default value if var is unset/null


echo ${asdf:-some default value}

panel 6: ${var:?some error}

prints “some error” and exits if var is null or unset

panel 7: ${var#pattern} and ${var%pattern}

remove the prefix/suffix pattern from `var.


$ x=motorcycle.svg
$ echo "${x%.svg}"

panel 8: ${var:offset:length}

get a substring of var. Example:

$ x='panda bear time'
$ echo ${x:6:4}

panel 9

person: “there are LOTS more, look up ‘bash parameter expansion’!”

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)