Debian Bug report logs -
#478096
bash: local does not work for some Bash variables
Reply or subscribe to this bug.
Toggle useless messages
Report forwarded to debian-bugs-dist@lists.debian.org, Matthias Klose <doko@debian.org>:
Bug#478096; Package bash.
(full text, mbox, link).
Acknowledgement sent to Morita Sho <morita-pub-en-debian@inz.sakura.ne.jp>:
New Bug report received and forwarded. Copy sent to Matthias Klose <doko@debian.org>.
(full text, mbox, link).
Message #5 received at submit@bugs.debian.org (full text, mbox, reply):
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
Send a report that this bug log contains spam.
Debian bug tracking system administrator <owner@bugs.debian.org>.
Last modified:
Sun Jul 2 09:15:00 2023;
Machine Name:
bembo
Debian Bug tracking system
Debbugs is free software and licensed under the terms of the GNU
Public License version 2. The current version can be obtained
from https://bugs.debian.org/debbugs-source/.
Copyright © 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson,
2005-2017 Don Armstrong, and many other contributors.