Re: !; is interpreted as an history expansion that can never match anything

2023-08-10 Thread Chet Ramey

On 8/8/23 3:30 PM, Dale R. Worley wrote:

Emanuele Torre  writes:

! followed by a ; or another terminator  is interpreted as an history
expansion with no pattern that can never match anything.

   $ !; echo hi
   bash: !: event not found
   $ !&& echo hi
   bash: !: event not found


IMHO it is more to the point that in the manual page it says

!string
   Refer  to the most recent command preceding the current position
   in the history list starting with string.

without defining "string".

It looks like the actual definition is "everything from the ! to the end
of the word", taking into account


I would have thought it obvious, since history expansion specifiers don't
span words.


The line is broken  into  words
in  the same fashion as when reading input, so that several metacharac‐
ter-separated words surrounded by quotes are considered one word.  His‐
tory  expansions are introduced by the appearance of the history expan‐
sion character, which is ! by default.

With the significant detail that the ! need not be the first character
of the word.


That's useful to add.



So I think the manual page could be improved by adding *...*:

!string
   Refer  to the most recent command preceding the current position
   in the history list starting with string.  *All characters
   until the start of the word designator or end of the word
   are part of string.*


It's more general than that: the event designator is the portion of the
word from the history expansion character to a word designator or the
end of the word.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: !; is interpreted as an history expansion that can never match anything

2023-08-09 Thread Chet Ramey

On 8/8/23 5:02 PM, Emanuele Torre wrote:

On Tue, Aug 08, 2023 at 03:35:10PM -0400, Chet Ramey wrote:

Anyway, there's a good reason to add ";&|" to the set of characters that
inhibit history expansion if they follow the history expansion character.


Thank you! Please also "()<>" if possible.


I think it's reasonable to add the shell metacharacters, since those will
separate words anyway.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: !; is interpreted as an history expansion that can never match anything

2023-08-08 Thread Emanuele Torre
On Tue, Aug 08, 2023 at 03:35:10PM -0400, Chet Ramey wrote:
> Anyway, there's a good reason to add ";&|" to the set of characters that
> inhibit history expansion if they follow the history expansion character.

Thank you! Please also "()<>" if possible.

o/
 emanuele6



Re: !; is interpreted as an history expansion that can never match anything

2023-08-08 Thread Chet Ramey

On 8/8/23 1:43 AM, Emanuele Torre wrote:

! followed by a ; or another terminator  is interpreted as an history
expansion with no pattern that can never match anything.

   $ !; echo hi
   bash: !: event not found
   $ !&& echo hi
   bash: !: event not found


This is interesting. Bash documents the same characters that inhibit
history expansion as tcsh (my reference for csh-style history expansion),
but tcsh adds `;' and `&' to that set. Its behavior with `|' is a little
wierd: if the command on the rhs of the pipeline is an external command,
you get a command not found error, but if it's a builtin, you don't.

Anyway, there's a good reason to add ";&|" to the set of characters that
inhibit history expansion if they follow the history expansion character.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/




Re: !; is interpreted as an history expansion that can never match anything

2023-08-08 Thread Dale R. Worley
Emanuele Torre  writes:
> ! followed by a ; or another terminator  is interpreted as an history
> expansion with no pattern that can never match anything.
>
>   $ !; echo hi
>   bash: !: event not found
>   $ !&& echo hi
>   bash: !: event not found

IMHO it is more to the point that in the manual page it says

   !string
  Refer  to the most recent command preceding the current position
  in the history list starting with string.

without defining "string".

It looks like the actual definition is "everything from the ! to the end
of the word", taking into account

   The line is broken  into  words
   in  the same fashion as when reading input, so that several metacharac‐
   ter-separated words surrounded by quotes are considered one word.  His‐
   tory  expansions are introduced by the appearance of the history expan‐
   sion character, which is ! by default.

With the significant detail that the ! need not be the first character
of the word.

So I think the manual page could be improved by adding *...*:

   !string
  Refer  to the most recent command preceding the current position
  in the history list starting with string.  *All characters
  until the start of the word designator or end of the word
  are part of string.*


   The line is broken  into  words
   in  the same fashion as when reading input, so that several metacharac‐
   ter-separated words surrounded by quotes are considered one word.  His‐
   tory  expansions are introduced by the appearance of the history expan‐
   sion character, which is ! by default*, within a word*.

Dale



!; is interpreted as an history expansion that can never match anything

2023-08-07 Thread Emanuele Torre
! followed by a ; or another terminator  is interpreted as an history
expansion with no pattern that can never match anything.

  $ !; echo hi
  bash: !: event not found
  $ !&& echo hi
  bash: !: event not found

It should not be intepreted as a history expansion that cannot possibly
match anything; it should work the same it works if there is a space
after `!', or if histexpand is off.

  $ ! ; echo "$?" hi
  1 hi
  $ ! && echo hi
  bash: syntax error near unexpected token `&&'

o/
 emanuele6