help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Adding a marker line to history at interactive shell sta


From: Dennis Williamson
Subject: Re: [Help-bash] Adding a marker line to history at interactive shell start (and history timestamps)
Date: Sat, 23 Jun 2012 19:27:14 -0500

On Sat, Jun 23, 2012 at 2:36 PM, Chet Ramey <address@hidden> wrote:
> On 6/21/12 9:56 PM, Dennis Williamson wrote:
>> I am trying to add a marker line to the bash history list when an
>> interactive (Bash) shell is started. When I try the commands shown
>> below, I get the line that I want, but their is no timestamp so the
>> output of the history command is wrong.
>>
>> In a file in /etc/profile.d which gets sourced by /etc/profile, I have
>> the following lines:
>>
>> HISTTIMEFORMAT='%c : '
>> set -o history
>> history -s "# some text as a marker with $vars"
>>
>> The comment line gets added, but their is no timestamp for it, so when
>> I issue the history command I get output such as the following:
>
> Try running `set -H' or adding an assignment to histchars:
> histchars='!^#'
> before the `history -s'.
>
> The history timestamp code prefixes the timestamp with the history comment
> character, but the history comment character is '\0' by default.  Later on,
> when bash does history initialization, it's set, but it's unchanged when
> the profile code is running.
>
> I wonder if it would be a good idea to set the history comment character
> to the bash default (`#') if it's '\0' when HISTTIMEFORMAT is set or
> modified.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>                 ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, ITS, CWRU   address@hidden    http://cnswww.cns.cwru.edu/~chet/
>
>

Thanks! It works great!

I tried set -H (and the equivalent set -o histexpand) and that worked.
I also tried assigning to histchars. That also worked and I prefer it.
This is on Bash 4.1

I think setting the history comment character in conjunction with
HISTTIMEFORMAT as you describe might be a good thing to do.

On other systems which have Bash 3.2.25(1)-release (IIRC), it works in
that ~/.bash_history gets the right information. However, issuing
history at the command line only shows the last commented line that's
contained in the history list and none from the history file (without
having tested the condition of none being present in the list since
that's not relevant for this). Do you know why this may be and what
might be done about it?

-- 
Visit serverfault.com to get your system administration questions answered.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]