Characters do not get escaped in HISTTIMEFORMAT

I have installed my first dualboot linux a couple of days ago. While I am customizing my terminal, I came by this problem. While escaping works correctly in the PS1 variable, it’s not working in the HISTTIMEFORMAT variable.

WHITE="\e[97m"
BOLD="\e[1m"
RESET="\e[0m"
PS1="$BOLD[\A - @\h:$WHITE\W\e[m]\n\\$ $RESET"
HISTTIMEFORMAT="$WHITE[%F %T] $RESET"

One way around this is using echo and -e as follows

HISTTIMEFORMAT=`echo -e $WHITE[%F %T] $RESET`

But I still want to know why the first method is not working?

1 Like
  1. In the future, when providing code/output, please copy-paste that output in-between 3 backticks ``` at the beginning and end of the code/text so that the output looks like this:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
    Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
    

    instead of like this:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

    (as that makes both our lives much easier)

  2. No need to do anything right now as I’m an editor here on this site and have fixed it for you already. However, in the future I might not see your post so review my edits by pushing the orange pencil above the post I just fixed. :wink:

  3. The history command is one of the oldest commands around and simply doesn’t support colour… Would be nice if it did though, but if I had wheels, I’d be a wagon, so your workaround is actually pretty nifty and I’m going to use it from now on!

:clap:

1 Like

Thanks for the formatting tips, and the answer.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.