[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Printing the date just before execution of commands in bash



On Sun, 15 Oct 2006, Jos�lburquerque wrote:

> Matus UHLAR - fantomas wrote:
>
> > tcsh has the feature of printing time automatically after each
> > command executed (time variable). it also has 'precmd' and 'postcmd'
> > aliases that are executed (if set) before and after any command
> > executed.
>
> [massive snippage]
>
> Anyway, it looks like tcsh has a lot more than bash in this area.  I
> may just give tcsh another try.  On the other hand, it's not that
> inconvenient to not be able to get this automatically in bash.  I
> would just have to remember to use the 'time' command when I really
> want to time something. :-)

zsh's preexec() function might help you out here. It runs after the
command has been read by the shell but just before it executes the
command. In fact, I just tried it at my shell and I can make it print
the date before each following command:

    revolver: /usr % preexec () { date }

Then:

    revolver: /usr % ls
    Sun Oct 15 22:18:28 CDT 2006
    X11R6           lib             sbin
    bin             libexec         share
    include         local           standalone
    revolver: /usr %

If you grew up on tcsh, you might like zsh a lot -- virtually all of the
features of tcsh, with Bourne-shell syntax. I learned tcsh first, and
then switched to zsh and never looked back.

- Aaron

-- 
Aaron Hall           :             Sleep, where is thy sting?
lisps@vitaphone.net  :             Bed, where is thy victory?
                     :                           -- Insomnia? Me?

Reply to: