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



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to