In tcsh, the built-in sched command causes a command to be executed by the current shell at a specified time.
I have the following $HOME/.sched file (this is a simplified version of it):
setenv today `date +%F`
sched +00:01 sched 00:00 source $HOME/.sched
I then source $HOME/.sched in my $HOME/.cshrc.
This sets the environment variable $today to, for example, "2012-06-25", and automatically updates it to the current date every night at midnight. The job automatically reschedules itself every time it runs.
Note that the date command is invoked only once each day, and only when it's needed.
Is there a way to do this in bash? Note that the at command won't work; it invokes a command externally and cannot affect the current shell's environment.
(I know that I can type $(date +%F) rather than $today, but since I use this interactively, the extra typing is a significant burden.)
tcsh also has a number of special aliases that are executed automatically in certain circumstances:
The beepcmd, cwdcmd, periodic, precmd, postcmd, and jobcmd Special aliases can be set, respectively, to execute commands when the shell wants to ring the bell, when the working directory changes, every tperiod minutes, before each prompt, before each command gets executed, after each command gets executed, and when a job is started or is brought into the foreground.
Does bash have anything like these?