Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have the following code in my bashrc to get the execution time of the last command from

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

1 Answer 1

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.