bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

! history expansion occurs within arithmetic substitutions


From: Zachary Santer
Subject: ! history expansion occurs within arithmetic substitutions
Date: Tue, 8 Aug 2023 09:24:48 -0400

Configuration Information:
Machine: x86_64
OS: msys
Compiler: gcc
Compilation CFLAGS: -march=nocona -msahf -mtune=generic -O2 -pipe
-D_STATIC_BUILD
uname output: MSYS_NT-10.0-19045 Zack2021HPPavilion 3.4.7.x86_64 2023-07-14
16:57 UTC x86_64 Msys
Machine Type: x86_64-pc-msys

Bash Version: 5.2
Patch Level: 15
Release Status: release

Description:
Similarly, history expansion occurs within arithmetic substitutions. This
will never, ever be what the user wants. And now I know how to make it not
happen.

Repeat-By:
$ set -o histexpand
$ number=4
$ printf '%s\n' "$(( !0 ))"
-bash: !0: event not found
$ (( !0 )); printf '%s\n' "${?}"
-bash: !0: event not found
$ printf '%s\n' "$(( !1 ))"
printf '%s\n' "$(( pacman -Suy ))"
0
$ printf '%s\n' "$(( !3 ))"
printf '%s\n' "$(( man pcre2grep ))"
-bash: man pcre2grep : syntax error in expression (error token is
"pcre2grep ")
$ printf '%s\n' "$(( !number ))"
printf '%s\n' "$(( number=4 ))"
4
$ set +o histexpand
$ printf '%s\n' "$(( !0 ))"
1
$ (( !0 )); printf '%s\n' "${?}"
0
$ printf '%s\n' "$(( !1 ))"
0
$ printf '%s\n' "$(( !3 ))"
0
$ printf '%s\n' "$(( !number ))"
0

I'm guessing this is a known issue, and would be a gigantic pain to fix.
Wanted to point it out, just in case.

While we're at it:
$ bashbug
/usr/bin/bashbug: line 135: [: missing `]'
/usr/bin/bashbug: line 137: [: missing `]'

- Zack

On Tue, Aug 8, 2023 at 1:44 AM Emanuele Torre <torreemanuele6@gmail.com>
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
>
> 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
>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]