#!/usr/bin/env bash shopt -s extglob nullglob add_to_list() { list=$(basename "$1") file=$(basename "$2") last_link=$(find ./lists/"$list" -regex '.*/[0-9]*$' -printf '%f\n' | sort | tail -n1) new_link=$(printf '%03d\n' $(($last_link + 1))) ln -s ../../posts/"$file" ./lists/"$list"/"$new_link" } new_post() { filename="$1" shift 1 cat >posts/$filename <&2 '%s: %s\n' "${0##*/}" "$OPTLERR" exit 1;; esac done