Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code in my bashrc to get the execution time of the last command from http://stackoverflow.com/a/1862762

function timer_start {

function timer_stop {
  timer_show=$(($SECONDS - $timer))
  unset timer

trap 'timer_start' DEBUG

PS1='[last: ${timer_show}s][\w]$ '

but when I run echo $_ it shows "timer_start" instead of the last commands parameter.

How can I change this to preserve the $_ variable?

share|improve this question
up vote 1 down vote accepted

You could do:

trap '__=$_; timer_start; : "$__"' DEBUG
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.