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