Jim Hall

Authored Content

Authored Comments

I also use gnome-terminal most of the time - but sometimes I'll use Cool Retro Term for that 80s throwback feel.

Great article!

The 'if' statement can come in really handy in all Bash scripts. And for very short 'if' statements, the && and || shortcuts are also useful. For example, I often do this when I need to be sure a directory exists:

[ -d "$1" ] || mkdir --parents "$1"

That statement create the directory only if it doesn't exist. You could also write the statement like this:

[ ! -d "$1" ] && mkdir --parents "$1"

The && means "if the test was true, then do the next statement." And the || means "if the test wasn't true, then do the next statement." You can think of them as "AND" and "OR" at the execution level.