help-bash
[Top][All Lists]
Advanced

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

Re: All bash variables that can be used as temp variables?


From: Koichi Murase
Subject: Re: All bash variables that can be used as temp variables?
Date: Wed, 25 Jan 2023 22:07:16 +0900

2023年1月22日(日) 6:47 Peng Yu <pengyu.ut@gmail.com>:
> https://lists.gnu.org/archive/html/help-bash/2023-01/msg00104.html
>
> As discussed here BASH_REMATCH is a temp variable that can be used to
> avoid polluting the global variable space.

BASH_REMATCH can be used to extract a part of the string using a
regular expression, but that doesn't mean it doesn't affect the global
variable space. It's actually the opposite. Currently, using regular
expressions in [[ ]] would always cause side effects in **BASH_REMATCH
of the global scope**. One needs to always copy the content of
BASH_REMATCH to other variables when one wants to use it after calling
some other functions.

> What other bash variables
> can be used as temp variables (not necessarily for the purpose of
> trimming prefixes and suffixes) to avoid polluting the global variable
> space?

If you mean that using BASH_REMATCH doesn't cause additional pollution
of the global space because it's already polluting the global space,
you could check the list of the already used global variable names in
Bash Reference Manual Sec. 5.2:

https://www.gnu.org/software/bash/manual/bash.html#Bash-Variables



reply via email to

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