0

Is there a way to concatenate time after command has been entered? Example:

user@machine$ date
11:50:41
Tue Jun 25 11:50:41 EEST 2019

Current workaround is to add \t\n to PS1 before the username but that is not quite what I want to achieve, as it might lie, especially when the processing takes time and has a lot of output, e.g. when apt is run after a hiatus.

One idea I had was to capture the input with read but execute it after the time was printed. One downside is the command is then entered/printed second time.

krg
  • 17
  • 4

1 Answers1

0
trap 'date +%T' DEBUG

Solution taken from answers to this question: Does bash have a hook that is run before executing a command?.

Kamil Maciorowski
  • 69,815
  • 22
  • 136
  • 202
  • Thank you, Kamil! The link you posted was helpful. Found [Bash-preexec](https://github.com/rcaloras/bash-preexec) through that but your solution is more elegant. – krg Jun 25 '19 at 10:35