#!/bin/sh # Shows the date for "fri week" or "mon last" for e.g. # License: LGPLv2 proc Usage { echo "Usage: $(basename $0) mon|tue|... [next]|week|last" >&2 exit 1 } test "$Argc" -eq "0" && Usage setvar day = "$1" setvar which = "$2" test -z $which && setvar which = 'next' case (which) { week { if test $(date +%D) = $(date --date="next $day" +%D) { setvar weeks = "+2" #assume we want the next week, not today } else { setvar weeks = "+1" } } last { setvar weeks = '-1'} next { if test $(date +%D) = $(date --date="next $day" +%D) { setvar weeks = "+1" #assume we want the next week, not today } else { setvar weeks = "+0" } } * { Usage} } date --date="$day $weeks weeks" +%x