0

In order to record date and time for each command in history I set

HISTTIMEFORMAT="%d/%m/%y %T"

And in order for this setting to remain after I log out or close the terminal I added to the .bashrc

echo "HISTTIMEFORMAT="%d/%m/%y %T"" >> .bashrc

I tested and it shows the time for commands in history,for those I used after I wrote the 2 commands above.Problem is after I open the terminal it gives me a message saying:

bash:fg:no job control

HISTTIMEFORMAT = "%d/%m/%y %T"

bash:fg:no job control  

HISTTIMEFORMAT = "%d/%m/%y %T"

bash:fg:no job control

I checked the history and it doesn't show me the date for the past commands anymore as it was supposed to do after I added to the bashrc file. I repeated the commands for the time format and each time it doesn't save and I think the more I add the command to the bashrc file the more that message is being expanded with that no job control thing.

Is there any way to fix this/reset the format? There is no whitespace around = and each time I insert that var to the file the more statements of no job control shows after I open the terminal even though it shows time during the session.It's like the var gets broken when exiting.

The end of the bashrc file is this:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
HISTTIMEFORMAT=%d/%m/%y %T
9
  • 2
    Your echo "HISTTIMEFORMAT="%d/%m/%y %T"" >> .bashrc will result in this being added to your .bashrc HISTTIMEFORMAT=%d/%m/%y %T (no quotes) which is why you are seeing the error. So just manually edit your .bashrc file and edit it to ensure you have only a single HISTTIMEFORMAT="%d/%m/%y %T" – codlord Feb 14 at 11:04
  • I read the file with cat .bashrc and it shows exactly what u mean,there is no echo before the var.I was told i need to write that command so the histtime would be active permanently. – Cristi Feb 14 at 11:06
  • 1
    As I said previously HISTTIMEFORMAT=%d/%m/%y %T (no quotes) needs to be HISTTIMEFORMAT="%d/%m/%y %T" (with quotes). – codlord Feb 14 at 11:21
  • 1
    bash reads quotes from left to right so... left right... first string will be "HISTTIMEFORMAT=" and middle part will be unquoted %d/%m/%y %T (the space will break the assignment of the variable) and last is "" empty. It should have been echo 'HISTTIMEFORMAT="%d/%m/%y %T"' >> ~/.bashrc – bac0n Feb 14 at 11:48
  • 2
    @bac0n thanks a lot.Your command fixed it! And ty for the explanation.No friend of mine knew this.Some of them actually recommended me to install zsh or ohmyzsh to fix it. – Cristi Feb 14 at 13:10
0

The command should've been written like this in order to be under quotes in bashrc file

echo 'HISTTIMEFORMAT="%d/%m/%y %T"' >> ~/.bashrc

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