Print the absolute path of a file with realpath

TIL: use realpath to print the absolute path of a file. Useful for creating symlinks. for f in $(realpath scripts/linux/*); do ln -s "$f" ~/bin/$(basename "$f"); done

May 7, 2022 · Fernando Costa Bertoldi

Shellcheck

Used shellcheck, a shell linter, very useful.

April 12, 2022 · Fernando Costa Bertoldi

Pretty-print tabular output with column

TIL: pipe output of commands that are tabular to the column command to make them more readable

April 6, 2022 · Fernando Costa Bertoldi

Resolve the path os symlinks with readlink

TIL: use the readlink command to resolve symbolic links to executables. Use the -f option to follow the link recursively. # find the path to the youtube-dl script. readlink -f $(which yt-dlp)

April 6, 2022 · Fernando Costa Bertoldi

: (colon) on bash

https://stackoverflow.com/questions/3224878/what-is-the-purpose-of-the-colon-gnu-bash-builtin https://unix.stackexchange.com/questions/31673/what-purpose-does-the-colon-builtin-serve Historically, Bourne shells didn’t have true or false as built-i commands. true was simply aliased to : : is slightly better than true for portability. Uses: # alias to true while : ; do command ; done # variable expansion, assign default value var= : ${var:=DEFAULT} echo $var DEFAULT

Fernando Costa Bertoldi

Expand the last argument of previous command with $_

Last monday I learned that $_ in a script expands to the last argument of the previous command

Fernando Costa Bertoldi

sh: regexp match

TIL: to regexp match a string and use it as a condition, pipe it to grep -Eq $ protoc --version | cut -d' ' -f2 | grep -Eq ${PROTOC_VERSION} || { echo 'Incompatible protoc version'; exit 1; }

Fernando Costa Bertoldi