Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Dec 2016 08:35:09 +0000
From:      bugzilla-noreply@freebsd.org
To:        freebsd-bugs@FreeBSD.org
Subject:   [Bug 215207] [patch] getopt(1) example mangles command-line arguments with embedded spaces
Message-ID:  <bug-215207-8@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D215207

            Bug ID: 215207
           Summary: [patch] getopt(1) example mangles command-line
                    arguments with embedded spaces
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Keywords: patch
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs@FreeBSD.org
          Reporter: dds@FreeBSD.org
          Keywords: patch

Created attachment 177862
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D177862&action=
=3Dedit
Proposed fix

The provided getopt(1) example in the manual page mangles command-line
arguments containing spaces by splitting them through IFS.

Consider the following minimal example script, written by following the man
page example.

#!/bin/sh
args=3D`getopt a: $*`
if [ $? -ne 0 ]; then
   echo 'Error'
   exit 2
fi

set -- $args
while :; do
   case "$1" in
   -a)
           flags=3D-a
           shift
           ;;
   --)
           shift; break
           ;;
   esac
done

for i; do
    echo "Arg $i"
    shift
done

When the above script is run with 'a b' as an argument, it will output
Arg a
Arg b
rather than
Arg a b

The problem can be fixed by applying the attached patch.  Note that the pat=
ch
does not address option arguments with embedded spaces.

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-215207-8>