Search code examples
bashescapingcommand-substitutionps1

BASHRC PS1 show datetime but plus 3 hours


Every of us set own convenience working with Linux shell, for example I use /root/.bashrc

PS1='[\h:\w] \D{%F %T}\n\$ '

to show servername + current server datetime + newline for command - so it looks like

[servername217:~] 2022-02-06 00:55:02
#

But I met a stumbling block with syntax trying to set not server time, but my home, for example plus 3 hours. It's easy to make with regular BASH

date -d '+ 3 hour' '+%F %T'

but when I try to use, for example,

PS1='[\h:\w] [date -d '+ 3 hour' '+%F %T']\n\$ '

I always get an error. It seems PS1 understands only

\D{%F %T}

but how to add 3 hours to %T under this format ? Or there is an another way ?


Solution

  • This might help:

    PS1="[\h:\w] \$(date -d '+ 3 hour' '+%F %T')\n\$ "