Configuration Information [Automatically generated, do not change]: Machine: i486OS: linux-gnuCompiler: gccCompilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Walluname output: Linux emperor 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:57:59 UTC 2009 i686 GNU/LinuxMachine Type: i486-pc-linux-gnu Bash Version: 3.2Patch Level: 48Release Status: release Description: (Also reproduced in bash 4.0.16(1)-release on Fedora 11 when HISTCONTROL=ignorespace.) In a script that I developed which adds comments to the ends ofbash history entries, if the entry contains a newline, history -s givesdifferent results than if the entry does not contain a newline. Specifically, the entry is duplicated (with comment added) when there's a newline. The expected behavior is that the existing entry would be replaced by the comment-appended version as it correctly is when there's no newline. I have attached a test script below which duplicates the pertinentparts of my script, leaves out what isn't applicable to this problem, and includes various features to aid in reproducing the problem. It also includes further details of this issue. Repeat-By: Follow the steps outlined in the comments of the test script below.Fix: Unknown.
Attachment: # BEGINNING OF SCRIPT histt histt() {# adds comments to history entries, runs from PROMPT_COMMAND # demonstrates how HISTCONTROL ignorespace differs between# commands that include a newline and those that don't when# history -s is used within PROMPT_COMMAND # PROMPT_COMMAND is automatically set to run this function when# this file is sourced. When the function is run, it resets PROMPT_COMMAND# to its previous value and unsets itself (plays_well_with_others++) # This function does, however, make changes to your history (plays_well_with_others--) # test this in two rounds (A and B) # in round A, don't put an argument after histt # in round B, put any argument after histt (an "x" will do) # this argument controls whether a space is added to the command# stored by the history -s command in order to show the differences in behavior # in each round, perform tests one and two at a bash prompt as follows# (the dollar sign represents PS1, the > represents PS2 as issued by bash) # test one:# $ echo MARK# $ echo "a b";. ./histt # test two:# $ echo MARK# $ echo "a# > b";. ./histt # RESULTS: # | no newline (one) | newline (two)# ---------------+--------------------+------------------# no space (A) | comment added | dup. and add# space (B) | removes entry | entry not changed # EXPECTED: # | no newline (one) | newline (two)# ---------------+--------------------+------------------# no space (A) | comment added | comment added# space (B) | unknown - needs | unknown - needs# | to be consistent | to be consistent # The purpose of the space/no-space comparison is for completeness and to show# that the behavior also differs there. # tested under bash 3.2.48(1)-release in Ubuntu 9.04 (default HISTCONTROL=ignoreboth)# and bash 4.0.16(1)-release in Fedora 11 (default HISTCONTROL is unset, I set it to ignorespace for this test) local space=''space="${1:+ }" # set space to a space of there's a $1 local hist local comment hist=$(history 1) hist="${hist# *[0-9]* }" echo "....before...." history 3 comment="some comment" history -s "$space$hist # $comment" echo "....after...." history 3 # put things back like you found them PROMPT_COMMAND=$previous_prompt_command unset previous_prompt_command unset histt}previous_prompt_command=$PROMPT_COMMANDPROMPT_COMMAND="histt $1" # set up and run it # END OF SCRIPT histt