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: ! history expansion occurs within arithmetic substitutions

2023-08-10 Thread Dale R. Worley
Zachary Santer  writes:
> When messing around in interactive mode to test things I may want to do in
> a script, it's nice if it actually behaves the same. There are probably
> some other set and possibly shopt things I should have somewhere if that's
> what I want.

I checked, and it doesn't seem that there's an explicit way to start
bash noninteractively, but running "cat | bash" seems to work.  Of
course, it's noninteractive, so you get e.g. empty prompt strings!

My understanding is that "interactive" directly affects only two things,
the startup file(s) read and the initial values of various shell
options.  You can fix the startup files with explicit options on
invocation, and you can fix the shell options that matter to you with
commands.

Dale



Re: ! history expansion occurs within arithmetic substitutions

2023-08-10 Thread Lawrence Velázquez
On Thu, Aug 10, 2023, at 2:21 PM, Dale R. Worley wrote:
> My understanding is that "interactive" directly affects only two things,
> the startup file(s) read and the initial values of various shell
> options.

There are more differences than that.

https://www.gnu.org/software/bash/manual/html_node/Interactive-Shell-Behavior.html

-- 
vq