Print time after command has been entered

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

Posted 2019-06-25T09:00:16.413

Reputation: 7

Answers

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

Posted 2019-06-25T09:00:16.413

Reputation: 38 429

Thank you, Kamil! The link you posted was helpful. Found Bash-preexec through that but your solution is more elegant.

– krg – 2019-06-25T10:35:55.030