Your message dated Tue, 18 Dec 2007 19:28:54 -0500
with message-id <[EMAIL PROTECTED]>
and subject line Close: getopt and parameters with spaces
has caused the attached Bug report 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 I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: util-linux
Version: 2.13-8
Severity: normal


Hi, 

I seem to have found a bug of getopt from the util-linux
package. Please correct me if I'm wrong. 

I believe that the suggested way to call getopt is 

 eval set -- `getopt -o <options> -- "$@"`

But I found that it can't handle parameters with spaces well:

 $ set -- -t 'test p  1' 2

 $ getopt -o t: -- "$@"
  -t 'test p  1' -- '2'

Ok, so far so good, but:

 $ eval set -- `getopt -o t: -- "$@"`

 $ echo "'$2'"
 'test p 1'

I.e., the parameter passed is "test p  1", but after the parameter
parsing, it becomes "test p 1" -- one space missing before '1'.

Comment?

(Please reply publicly to [EMAIL PROTECTED])

Thanks

Tong

$ bash --version
GNU bash, version 3.1.17(1)-release (i486-pc-linux-gnu)

$ apt-cache policy bash
bash:
  Installed: 3.1dfsg-8
  Candidate: 3.1dfsg-8
  Version table:
 *** 3.1dfsg-8 0
        600 http://gulus.usherbrooke.ca lenny/main Packages
         50 http://gulus.usherbrooke.ca unstable/main Packages
        100 /var/lib/dpkg/status

$ apt-cache policy util-linux
util-linux:
  Installed: 2.13-8
  Candidate: 2.13-8
  Version table:
     2.13-13 0
         50 http://gulus.usherbrooke.ca unstable/main Packages
 *** 2.13-8 0
        600 http://gulus.usherbrooke.ca lenny/main Packages
        100 /var/lib/dpkg/status
     2.12r-19+lenny1 0
        600 http://security.debian.org lenny/updates/main Packages


-- System Information:
Debian Release: 4.0
  APT prefers testing
  APT policy: (600, 'testing'), (50, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17-grml
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages util-linux depends on:
ii  libc6    2.6.1-1+b1                      GNU C Library: Shared libraries
ii  libncurs 5.6+20070716-1                  Shared libraries for terminal hand
ii  libselin 2.0.15-2+b1                     SELinux shared libraries
ii  libslang 2.0.7-3                         The S-Lang programming library - r
ii  libuuid1 1.39+1.40-WIP-2006.11.14+dfsg-2 universally unique id library
ii  lsb-base 3.1-24                          Linux Standard Base 3.1 init scrip
ii  tzdata   2007f-10                        time zone and daylight-saving time
ii  zlib1g   1:1.2.3.3.dfsg-5                compression library - runtime

util-linux recommends no packages.

-- no debconf information




--- End Message ---
--- Begin Message ---
>> I believe that the suggested way to call getopt is 
>> 
>>  eval set -- `getopt -o <options> -- "$@"`
> 
> No, it is actually: 
>   eval set -- "`getopt -o <options> -- "$@"`"
> 
> Note the extra set of double quotes!

Sill me. Full reply enclosed below:

From: Frodo Looijaard <frodo <at> frodo.looijaard.name>
Subject: Re: getopt and parameters with spaces
Newsgroups: gmane.linux.debian.user
Date: 2007-12-18 20:09:58 GMT

On Mon, Dec 17, 2007 at 06:29:01PM -0500, T o n g wrote:

> I seem to have found a bug of getopt from the util-linux
> package. Please correct me if I'm wrong. 
> 
> I believe that the suggested way to call getopt is 
> 
>  eval set -- `getopt -o <options> -- "$@"`

No, it is actually: 
  eval set -- "`getopt -o <options> -- "$@"`"

Note the extra set of double quotes!

See also the example script (on debian installed in
/usr/share/doc/util-linux/examples/getopt-parse.bash.gz), which does it
in two steps, in order to preserve the return code:

  TEMP=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
       -n 'example.bash' -- "$@"`

  if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

  # Note the quotes around `$TEMP': they are essential!
  eval set -- "$TEMP"

That remark about the quotes is not there by accident :-)

 
> But I found that it can't handle parameters with spaces well:
> 
>  $ set -- -t 'test p  1' 2

[..]

>  $ eval set -- `getopt -o t: -- "$@"`
> 
>  $ echo "'$2'"
>  'test p 1'

Correct. But with the extra double quotes around the backquotes, it
preserves the spaces correctly.

Have fun,
  Frodo

-- 
Frodo Looijaard 


--- End Message ---

Reply via email to