From owner-svn-src-stable@FreeBSD.ORG Sun Feb 13 19:07:17 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E476810656C0; Sun, 13 Feb 2011 19:07:17 +0000 (UTC) (envelope-from uqs@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B81B08FC08; Sun, 13 Feb 2011 19:07:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p1DJ7HFQ048619; Sun, 13 Feb 2011 19:07:17 GMT (envelope-from uqs@svn.freebsd.org) Received: (from uqs@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p1DJ7Hpa048617; Sun, 13 Feb 2011 19:07:17 GMT (envelope-from uqs@svn.freebsd.org) Message-Id: <201102131907.p1DJ7Hpa048617@svn.freebsd.org> From: Ulrich Spoerlein Date: Sun, 13 Feb 2011 19:07:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218657 - stable/7/usr.bin/getopt X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Feb 2011 19:07:18 -0000 Author: uqs Date: Sun Feb 13 19:07:17 2011 New Revision: 218657 URL: http://svn.freebsd.org/changeset/base/218657 Log: MFH r209772,217890 Fix an error in the EXAMPLES section of getopt(1), which is based on the same fix present in NetBSD. Fix typo in example getopt(1) script: $i vs $1 [1] While here apply style hammer. PR: docs/133118, docs/154289 [1] Submitted by: Oleg A. Mamontov, Jamie Landeg Jones Modified: stable/7/usr.bin/getopt/getopt.1 Directory Properties: stable/7/usr.bin/getopt/ (props changed) Modified: stable/7/usr.bin/getopt/getopt.1 ============================================================================== --- stable/7/usr.bin/getopt/getopt.1 Sun Feb 13 19:02:26 2011 (r218656) +++ stable/7/usr.bin/getopt/getopt.1 Sun Feb 13 19:07:17 2011 (r218657) @@ -1,6 +1,6 @@ .\" $FreeBSD$ .\" -.Dd April 3, 1999 +.Dd January 26, 2011 .Dt GETOPT 1 .Os .Sh NAME @@ -55,8 +55,7 @@ which requires an argument. args=\`getopt abo: $*\` # you should not use \`getopt abo: "$@"\` since that would parse # the arguments differently from what the set command below does. -if [ $? -ne 0 ] -then +if [ $? -ne 0 ]; then echo 'Usage: ...' exit 2 fi @@ -64,22 +63,23 @@ set \-\- $args # You cannot use the set command with a backquoted getopt directly, # since the exit code from getopt would be shadowed by those of set, # which is zero by definition. -for i -do - case "$i" - in - \-a|\-b) - echo flag $i set; sflags="${i#-}$sflags"; - shift;; - \-o) - echo oarg is "'"$2"'"; oarg="$2"; shift; - shift;; - \-\-) - shift; break;; +while true; do + case "$1" in + \-a|\-b) + echo "flag $1 set"; sflags="${1#-}$sflags" + shift + ;; + \-o) + echo "oarg is '$2'"; oarg="$2" + shift; shift + ;; + \-\-) + shift; break + ;; esac done -echo single-char flags: "'"$sflags"'" -echo oarg is "'"$oarg"'" +echo "single-char flags: '$sflags'" +echo "oarg is '$oarg'" .Ed .Pp This code will accept any of the following as equivalent: