Your message dated Thu, 21 Mar 2024 18:14:35 +0100
with message-id <[email protected]>
and subject line Re: Bug#478096: bash: local does not work for some Bash
variables
has caused the Debian Bug report #478096,
regarding bash: local does not work for some Bash variables
to be marked as done.
This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.
(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)
--
478096: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=478096
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: bash
Version: 3.2-2
Severity: normal
Hello,
local built-in command does not work for some Bash variables.
As I understand it,
local built-in makes a variable local for the function,
and that variables will be restored to its previous value when returned from
that function.
However, it not work for some variables that used to change the behavior of
Bash.
For example, since LC_ALL variable changes the behavior of some string
operation in Bash,
I made a function that has "local LC_ALL=C" to temporary change the behavior of
the string operation,
but the behavior of Bash will not be restored after returned from that function,
Bash still behaves as LC_ALL=C.
#
# Here is a testcase using LC_ALL
#
# A variable contains multibyte characters.
MULTIBYTE_VALUE="ÀÈÒ"
# LC_ALL is not defined at this point.
declare -p LC_ALL
=> bash: declare: LC_ALL: not found
# ${parameter:offset} does character oriented operation.
echo "${MULTIBYTE_VALUE:1}"
=> ÈÒ
# Create and call a function that set LC_ALL=C locally.
local_lc_all() {
local LC_ALL=C
declare -p LC_ALL
=> declare -- LC_ALL="C"
# In C locale, ${parameter:offset} does byte oriented operation.
echo "${MULTIBYTE_VALUE:1}"
=> ?ÈÒ
}
local_lc_all
# LC_ALL has been restored to not defined.
declare -p LC_ALL
=> bash: declare: LC_ALL: not found
# This operation should print ÈÒ
echo "${MULTIBYTE_VALUE:1}"
=> ?ÈÒ
# ...but still does byte oriented operation.
#
# Here is a testcase using GLOBIGNORE
#
# Setup some files and directory.
mkdir test
cd test
touch a1 a2 a3 b1 b2 b3
# GLOBIGNORE is not defined.
declare -p GLOBIGNORE
=> bash: declare: GLOBIGNORE: not found
# * is expanded to all files in this directory.
ls *
==> a1 a2 a3 b1 b2 b3
# Create and call a function that set GLOBIGNORE locally.
local_globignore() {
local GLOBIGNORE="a*"
declare -p GLOBIGNORE
=> declare -- GLOBIGNORE="a*"
# A file that matches a* will be excluded in * expansion.
ls *
=> b1 b2 b3
}
local_globignore
# GLOBIGNORE has been restored to not defined.
declare -p GLOBIGNORE
=> bash: declare: GLOBIGNORE: not found
# But * is still expanded to "b1 b2 b3"
ls *
=> b1 b2 b3
This problem also affects to POSIXLY_CORRECT and IGNOREEOF variable.
But not affect to PATH and IFS variable.
Regards,
-- System Information:
Debian Release: lenny/sid
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.24-1-686 (SMP w/1 CPU core)
Locale: LANG=ja_JP.UTF-8, LC_CTYPE=ja_JP.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages bash depends on:
ii base-files 4.0.3 Debian base system miscellaneous f
ii debianutils 2.28.4 Miscellaneous utilities specific t
ii libc6 2.7-10 GNU C Library: Shared libraries
ii libncurses5 5.6+20080419-2 Shared libraries for terminal hand
Versions of packages bash recommends:
ii bash-completion 20060301-4 programmable completion for the ba
-- no debconf information
--- End Message ---
--- Begin Message ---
Version: 5.0-6
On Sun, 27 Apr 2008 11:36:45 +0900 Morita Sho
<[email protected]> wrote:
Package: bash
Version: 3.2-2
Severity: normal
Hello,
local built-in command does not work for some Bash variables.
As I understand it,
local built-in makes a variable local for the function,
and that variables will be restored to its previous value when returned from
that function.
However, it not work for some variables that used to change the behavior of
Bash.
For example, since LC_ALL variable changes the behavior of some string
operation in Bash,
I made a function that has "local LC_ALL=C" to temporary change the behavior of
the string operation,
but the behavior of Bash will not be restored after returned from that function,
Bash still behaves as LC_ALL=C.
This issue does not seem to affect version 5.0-6 and later of bash.
$ mkdir -p /tmp/x && cd /tmp/x && touch a1 a2 a3 b1 b2 b3
$ declare -p GLOBIGNORE; ls *
-bash: declare: GLOBIGNORE: not found
a1 a2 a3 b1 b2 b3
$ g() { local GLOBIGNORE="a*"; declare -p GLOBIGNORE ;ls * ; } ; g
declare -- GLOBIGNORE="a*"
b1 b2 b3
$ declare -p GLOBIGNORE; ls *
-bash: declare: GLOBIGNORE: not found
a1 a2 a3 b1 b2 b3
Please reopen this bug if you can still replicate this issue.
Regards,
--
Gioele Barabucci
--- End Message ---