After years of complaining that the internet lacked a sarcasm font it seems we’ve decided on random mixed case for denoting sarcasm.
Clearly we need a shell script to do this.
Or rather, “cLearLY wE neeD a SheLl sCrIpT to do tHiS.”
But I do find it useful, hence this recent addition to my home dir -
~/bin/sarcasm
:
|
|
In doing this I learned two new tricks. You can change case just with
bash by doing ${var^[a-z]}
or ${var,[A-Z]}
. By doing the caret or
comma twice you can affect all matches.
I also learned grep -o
which will emit matched text, not matched lines.
So echo foo bar foo | grep -o foo
will emit two foo
’s which might be
a good way to avoid sed
in some circumstances. Not sure if this is
a GNU grep extension though.
No matter what language I code in, I keep learning new tricks.
Edit: Fixed the bug where I’d reversed the case matching. I realised I
could just replace the [a-z]
syntax with just a *
- it takes globs
not REs.