Your message dated Wed, 27 Jun 2012 11:15:16 +0000 (UTC)
with message-id <[email protected]>
and subject line pdksh: bizarre behavior of getopt in shell functions
has caused the Debian Bug report #47848,
regarding bash: bizarre behavior of getopt in shell functions
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.)


-- 
47848: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=47848
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: bash
Version: 2.02.1-1.8
Severity: normal

Consider this shell script:

--
fun_a () {
        while getopts ksgq opt
        do      echo $opt
        done
}

fun_b () {
        while getopts a: opt
        do      echo $opt $OPTARG
        done
        shift `expr $OPTIND - 1`
        echo "$@"
        fun_a -k -sg
}

fun_b
echo
fun_b -a blah
echo
fun_b -a blah bar
--

I expected it to print this:
$ att-ksh test.sh

k
s
g

a blah

k
s
g

a blah
bar
k
s
g
$

but I got this:
$ bash test.sh

k
s
g



bar
$

Please fix.

zw

-- System Information
Debian Release: potato
Kernel Version: Linux zack 2.2.13pre15 #1 Mon Oct 4 22:12:49 PDT 1999 i686 
unknown

Versions of the packages bash depends on:
ii  libc6           2.1.2-5        GNU C Library: Shared libraries and timezone
ii  libncurses4     4.2-3.4        Shared libraries for terminal handling

--- End Message ---
--- Begin Message ---
Hi,

this is not a bug, cf. man mksh:

     Functions defined with the function reserved word are treated differently
     in the following ways from functions defined with the () notation:
[…]
     ·   OPTIND is saved/reset and restored on entry and exit from the func-
         tion so getopts can be used properly both inside and outside the
         function (Bourne-style functions leave OPTIND untouched, so using
         getopts inside a function interferes with using getopts outside the
         function).

Changing your script to read “function fun_a {” (and fun_b) makes
it behave as you expect.

bye,
//mirabilos
-- 
13:37⎜«Natureshadow» Deep inside, I hate mirabilos. I mean, he's a good
guy. But he's always right! In every fsckin' situation, he's right. Even
with his deeply perverted taste in software and borked ambition towards
broken OSes - in the end, he's damn right about it :(! […] works in mksh


--- End Message ---

Reply via email to