bug-bash
[Top][All Lists]
Advanced

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

Re: History Expansion in Arithmetic Expansion


From: Lawrence Velázquez
Subject: Re: History Expansion in Arithmetic Expansion
Date: Sat, 23 Mar 2024 14:48:17 -0400
User-agent: Cyrus-JMAP/3.11.0-alpha0-332-gdeb4194079-fm-20240319.002-gdeb41940

On Sat, Mar 23, 2024, at 11:34 AM, A4-Tacks wrote:
> Description:
>      I am unable to use logical inversion operators in line
>      arithmetic extensions, nor can I escape them, which is undoubtedly 
> abnormal
>
> Repeat-By:
>      ```bash
>      $ ((!RANDOM))
>      bash: !RANDOM: event not found
>      ```

Unfortunately this is intentional and documented.  In interactive
shells with default settings, unquoted `!' introduces a history
expansion [1].  You cannot backslash-escape `!' within `((exp))'
because `exp' is treated almost [*] as if it were double-quoted,
and within double quotes `\' escapes `!' but is not removed [3].

[1]: https://www.gnu.org/software/bash/manual/html_node/History-Interaction.html
[2]: 
https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html
[3]: https://www.gnu.org/software/bash/manual/html_node/Double-Quotes.html

[*]: One exception is that double quotes themselves are removed,
so another (arguably worse) workaround is `(("!"RANDOM))'.

-- 
vq



reply via email to

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