Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Geir Hauge Newsgroups: gnu.bash.bug Subject: Re: trap DEBUG and $_ Date: Mon, 12 Oct 2015 09:13:58 +0200 Lines: 32 Approved: bug-bash@gnu.org Message-ID: References: NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1444634053 31328 208.118.235.17 (12 Oct 2015 07:14:13 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Dan Stromberg Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=vNjj9ppN4UJ1RIe2/j4dTvHvnjOqj2WO2n6Z8mBwOZs=; b=Oqy2/pssSEBQqo07hSN66qDGIv2sGdXC+omoMXBdBsi6BhdyQ1HH72b3fl7qKvOViw NuoIi9BYZeDYbwTP3X4KHj80aud2OT2CzS1Q4nrbt5xrEV7g5sDt2ZI2ozaiq1Uc2674 IG2bMMCey1ycw9E35KtC/cSEhSIRwQF3rcv3Htot/514QeBSaP6mnjZFzYcr3hhN1v4F 7t96fEU6Du5k5NU9pHhKD5Ee9H3U4g6Yp61lPBiHBh+7UIdljmVZvu6LNwNWYuYXfmAN 1263dGC4LTNy9iHYYEN1UDIy0MyT/33g6GSuDkU8bcQx1nEoTnAspGdxtmy8RjvBh+35 utkQ== X-Received: by 10.112.132.74 with SMTP id os10mr11713162lbb.40.1444634043080; Mon, 12 Oct 2015 00:14:03 -0700 (PDT) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::233 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11624 On Mon, Oct 12, 2015 at 07:24:00AM +0200, isabella parakiss wrote: > On 10/11/15, Dan Stromberg 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