Rob Young | digital

Personal Reference

I find myself searching for the same bits of documentation again and again. This page is a collection of the things I find myself looking up most often.

Python

f-strings

Comprehensions

Nested comprehensions

[
  item 
  for inner in outer
  for item in inner
]

Special methods

Special method names

Bash

Escape single quotes

Since Bash 2.04 some escapes are allowed in $ strings.


> echo $'foo \'bar\' foo'
foo 'bar' foo

Iterate over files with spaces the names

This is usually good enough for my uses. Taken from this amazing StackExchange answer.

find . -type f -name "*.csv" -print0 | while IFS= read -r -d '' file; do
    echo "file = $file"
    diff "$file" "/some/other/path/$file"
    read line </dev/tty
done

Shellcheck warning pages

https://www.shellcheck.net/wiki/

These pages give the full help pages for each shellcheck lint, including the correct code to use.