Re: How to run something before invoking the inputted command?
From:
Greg Wooledge
Subject:
Re: How to run something before invoking the inputted command?
Date:
Mon, 12 Jul 2010 08:16:55 -0400
User-agent:
Mutt/1.4.2.3i
On Sat, Jul 10, 2010 at 11:22:27AM +0800, Clark J. Wang wrote:
> For example, in the interactive shell, I want to track the time when every
> inputted command is invoked. So I want to run a `date' command before
> actually invoking the inputted command. For now I have to do like this:
>
> $ date; command1
> $ date; command2
You could set a DEBUG trap.
trap 'date +%H:%M:%S' DEBUG
> On Sat, Jul 10, 2010 at 11:30 AM, Eric Blake <eblake@redhat.com> wrote:
> > Not quite before the command, but it is very easy to include $(date) as
> > part of PS1 to have a timestamp listed in the prompt that is printed
> > after every command.
On Sat, Jul 10, 2010 at 11:54:05AM +0800, Clark J. Wang wrote:
> Yes, timestamp in PS1 is fine for after-command purposes. And actually I use
> the PROMPT_COMMAND var for that.
unset PROMPT_COMMAND
PS1='$(date +%H:%M:%S)|\h:\w\$ '
Personally I've never found any use for PROMPT_COMMAND. It seems klunky
and awkward.