Bash Uppercase Input with Defaults

April 25, 2019

I needed to modify a bash function that accepted user input, so that it uppercased that input. This was implemented using a function that provided a default value.

   local entered_value
   read -p "$1 [default: $2]: " entered_value
   export $3="${entered_value:-$2}"
   export $3="${!3^^}"

fetchInputUpper "Enter Text?" "Default" VARIABLE
echo ...

Uppercase In Bash

April 25, 2019

If your bash version is greater than 4.0, you can use the ^^ syntax to uppercase variable values:

export LOWER="abc"
export UPPER=${LOWER^^}
echo $UPPER

Django Code Coverage

April 19, 2019

I have a Django application with tests, and I wanted to see what my code coverage was when those tests are run. This is fairly straightforward.

First, install coverage:

$ pip install coverage

Then, instead of running python test, run the following in the same directory:

$ coverage run --source ...

Mac Disk Usage One Level

March 24, 2019

I'm used to using du --max-depth=1 on linux boxes, but it doesn't work on my mac.

You can get the same values using du -hd1


Tags: du macos depth

Revert Latest Commit on a git repo

February 19, 2019

I have changes committed to my branch that I want to revert.

$ git checkout HEAD~1 -- filename.txt

This will look at the file filename.txt, look back one commit from HEAD, and then replace the contents of filename.txt with that version one commit back.