Chet Ramey <chet.ra...@case.edu> writes:
>> While declaring a string literal across multiple lines, a line starting
>> with the ^ character is resulting in some sort of quick substitution
>> processing.
>
> This is a standard form of history expansion, described in the man page.

I just checked.  Certainly, the use of ^ is mentioned in the man page,
but it isn't very clearly described, unfortunately.  In particular, ^ is
only active at the beginning of a line, which doesn't seem to be
described at all.  The only relevant passages seem to be:

       histchars
              The  two or three characters which control history expansion and
              tokenization (see HISTORY EXPANSION below).  The first character
              is  the history expansion character, the character which signals
              the start of a history  expansion,  normally  `!'.   The  second
              character  is the quick substitution character, which is used as
              shorthand for re-running the previous command  entered,  substi‐
              tuting  one  string  for another in the command.  The default is
              `^'.  [...]

Note that this doesn't mention that ^ has to appear at the beginning of
a line.  The other passage is:

   Event Designators
       An event designator is a reference to a command  line  entry  in  the
       history  list.  Unless the reference is absolute, events are relative
       to the current position in the history list.

       !      Start a history substitution, except when followed by a blank,
              newline,  carriage  return, = or ( (when the extglob shell op‐
              tion is enabled using the shopt builtin).
       !n     Refer to command line n.
       !-n    Refer to the current command minus n.
       !!     Refer to the previous command.  This is a synonym for `!-1'.
       !string
              Refer to the most recent command preceding the  current  posi‐
              tion in the history list starting with string.
       !?string[?]
              Refer  to  the most recent command preceding the current posi‐
              tion in the history list containing string.   The  trailing  ?
              may be omitted if string is followed immediately by a newline.
              If string is missing, the string from the most  recent  search
              is used; it is an error if there is no previous search string.
       ^string1^string2^
              Quick  substitution.   Repeat  the previous command, replacing
              string1 with string2.  Equivalent to ``!!:s^string1^string2^''
              (see Modifiers below).
       !#     The entire command line typed so far.

A quick read suggests that "^string1^string2^" is an event designator
which presumably is "the thing that follows !", leading one to guess
that the syntax is "!^string1^string2^".  A more careful reading
reveals that the list of event designators all include the initial !,
which suggests that "^string1^string2^" alone is the correct syntax.
That's correct, but it doesn't reveal that it must be at the beginning
of a line.  Indeed, the ^ form really should be removed from that list
and mentioned as a separate thing.

Dale

Reply via email to