Package: posh
Version: 0.6.7
Severity: normal

$ local() { echo a; }
$ local a
$ "local" a
$

"local" is not a POSIX command, but I suspect it might be a
"debian policy" extension to POSIX which may explain why posh
has it.

Anyway, the above breaks POSIX conformance I think. POSIX only
allows "select" and "function" as possible non-standard
keywords.

If "local" were a keyword in posh, I would expect the first line
above to give an error and the 3rd line to output "a\n".

Note that the behavior of "local" differs in *every* shell that
has such a builtin.

Note that given that "local" is not POSIX and can be written as
a POSIX shell function with little effort if need be, it
shouldn't be needed as a builtin, IMO.

See for instance:

# this is like the "local" in pdksh, posh or ash, and unlike in
# bash or zsh (that initialise the variable to an empty string)
# or ksh93 or bash (that don't parse it as a builtin).
#
# variables starting with _l are reserved.
# functions to be declared as:
# declare funcname; f_funcname() { ... ; }

local() {
  for _lvar do
    if eval "[ -z \"\${_l${_l}${_lvar%%=*}++}\" ]"; then
      eval "_l$_l=\"\${_l$_l} \${_lvar%%=*}\""
      eval "_l$_l${_lvar%%=*}=\${${_lvar%%=*}++\$${_lvar%%=*}}"
    fi
    case $_lvar in
      (*=*) eval "${_lvar%%=*}=\${_lvar#*=}"
    esac
  done
}

call() {
  _l=$((${_l:-0} + 1))
  unset "_l$_l"
  _lfname=${1#f_}
  _lfstack=$_lfstack+$_lfname
  "$@"
  _lfstack=${_lfstack%+*}
  _lfname=${_lfstack##*+}
  local IFS=" "
  eval "_lvar=\${_l$_l}"
  for _lvar in $_lvar; do
    eval "$_lvar=\${_l$_l$_lvar}"
    if eval "[ -z \"\${$_lvar}\" ]"; then
      unset "$_lvar"
    else
      eval "$_lvar=\${$_lvar#+}"
    fi
    unset "_l$_l$_lvar"
  done
  unset "_l$_l"
  _l=$(($_l - 1))
}

declare() { eval "$1() { call f_$1 \"[EMAIL PROTECTED]"; }"; }


# usage example:

declare f; f_f() {
  local i
  i=$(($i + 1))
  echo $_lfstack $i
  [ "$i" -ge 10 ] || f
  echo $_lfstack $i
}

f

# Or:

IFS=+
call eval '
  local IFS=:
  set -f
  printf "<%s>\n" $PATH
'
echo "$IFS"

# or
call . some-file
# to have variables local during the execution of the sourced
# file...


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.25-rc8 (PREEMPT)
Locale: LANG=en_GB.ISO-8859-15, LC_CTYPE=en_US.ISO-8859-15 (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages posh depends on:
ii  debconf [debconf-2.0]         1.5.22     Debian configuration management sy
ii  libc6                         2.7-11     GNU C Library: Shared libraries

posh recommends no packages.

-- debconf-show failed



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

Reply via email to