I have the following code in my bashrc to get the execution time of the last command from https://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?


You could do:

trap '__=$_; timer_start; : "$__"' DEBUG

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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