Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #11624
| From | Geir Hauge <geir.hauge@gmail.com> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: trap DEBUG and $_ |
| Date | 2015-10-12 09:13 +0200 |
| Message-ID | <mailman.121.1444634053.7904.bug-bash@gnu.org> (permalink) |
| References | <CAEf4Emd6m+JZd3ECqYknU-P3Nz25zyNw+4-BG-0TKy+Fa1hFOg@mail.gmail.com> <CAAZkfoKMrqTdN4qNkqrwGvufJhqf-sw0euazH7nA1XZtXz6nLQ@mail.gmail.com> |
On Mon, Oct 12, 2015 at 07:24:00AM +0200, isabella parakiss wrote:
> On 10/11/15, Dan Stromberg <dstromberglists@gmail.com> wrote:
> > Is there a way of outputting a datestamp to shell stderr at the _beginning_
> > of the execution of a command, that won't wipe out $_?
> >
> > I use $_ quite a bit for the last argument to the previous command,
> > interactively. And I'd like to datestamp all my commands. Datestamping
> > after with $PS1 is easy, but datestamping before is a little harder.
> >
> > I've tried using:
> >
> > function preexec { if tty -s; then echo "$(tput smso)cmd started $(date
> > +%Y\ %a\ %b\ %d\ %r)$(tput rmso)"; fi; }
> > trap preexec DEBUG
> >
> > ...but as you might suspect, I'm finding that $_ is always "preexec" with
> > this enabled.
> >
> > Any suggestions?
> >
> > Thanks!
> >
> trap '__=$_; preexec; : "$__"' DEBUG
And since the preexec function ignores its arguments, it can be
shortened to:
trap 'preexec "$_"' DEBUG
--
Geir Hauge
Back to gnu.bash.bug | Previous | Next | Find similar
Re: trap DEBUG and $_ Geir Hauge <geir.hauge@gmail.com> - 2015-10-12 09:13 +0200
csiph-web