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!
read the transcript!
panel 1: a script’s arguments are in $1
, $2
, $3
, etc
./script.sh panda banana
$1
is "panda"
and $2
is "banana"
panel 2: arguments are great for making simple scripts
Here’s a 1-line svg2png
script that I use to convert SVGs to PNGs:
#!/bin/bash
inkscape "$1" -b white --export-png="$2"
I run it like this:
$ svg2png old.svg new.png
(arrow pointing to "$2"
: “always quote your variables!”)
panel 3: get all the arguments with "${@}"
ls --color "${@}"
panel 4: you can loop over arguments
for i in "${@}"
do
echo "$i"
done
panel 5: 1 line shell scripts are great
person: “I can write a tiny script so I don’t have to remember a long command!”
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!