On 15/04/2023 19:37, Greg Wooledge wrote:
On Sat, Apr 15, 2023 at 11:02:12AM +0000, davidson wrote:On Sat, 15 Apr 2023 Max Nikulin wrote:The problem is to prevent history expansion while keeping pattern matching (glob) active. du -ks -- .[!.]* | sort -n | tailAre there versions of bash that exhibit history expansion in the example above?Not that I've found. I tried 3.2 and 2.05b and they're both fine.
I am really sorry. I have checked the terminal app buffer where I was experimenting with history expansion and almost certainly I misinterpreted some result. I see that inside square brackets expansion of exclamation mark is suppressed when (and only when) it immediately follows the opening bracket. - [!c] is safe - [a-f!@1-2] and [0-9!] are affected by history expansion (and it is likely the source of my confusion) Useful shortcuts for experiments: - M-^ history-expand-line - C-/ undo When writing that message I decided to use the command where I usually need negation in interactive sessions. So thank you for drawing my attention that I was wrong. I decided that history expansion in [!c] is consistent with echo "Hello World!" in BASH Pitfalls https://mywiki.wooledge.org/BashPitfalls#echo_.22Hello_World.21.22 and statements in "History Expansion" section of the BASH manual (and the man page as well) info "(bash) History Interaction" https://www.gnu.org/software/bash/manual/html_node/History-Interaction.html
History expansion is performed immediately after a complete line is read, before the shell breaks it into words, and is performed on each line individually.
...
the history expansion character is also treated as quoted if it immediately precedes the closing double quote in a double-quoted string.
No exception for square brackets is mentioned.