Surviving bash

The flagship product of modern unix is certainly better than any other 80s shell



General, not macOS-specific or Linux-specific, and see also shells to yak-shave your way into whole other shell paradigms. Or fish for a less awful user experience.

I just don’t care enough to remember. This makes me a Bad Hacker.

Command line tips

See command lines which are mostly bash specific because everything is hard in bash.

bash history

Vars, expansions, filenames, whitespace hell

Tilde expansion

Tilde expansion is complicated. Best to avoid tildes and use ${HOME}.

files extension munging in bash

for file in *.html;
    mv "$file" "`basename $file .html`.txt";
done

or:

mv "$file" "${file%.html}.txt"

Don’t forget the quotes, or it will explode when you have spaces in your filenames and delete stuff that you loved. (I hate bash so hard. I should probably abandon it.)

For loops

Watch out for horrible problems with handling of delimeters. Anyway, for loops are not insane.

#!/bin/bash

for i in $( ls ); do
    echo item: $i
done

No comments yet. Why not leave one?

GitHub-flavored Markdown & a sane subset of HTML is supported.