On Fri, Apr 30, 2021 at 04:54:57PM +0200, Christian Weisgerber wrote:
> Marc Espie:
> 
> > Until a patch from naddy, I wasn't even aware of getopts in sh(1)
> 
> Let's start the discussion with this instead.
> 
> This puts the deprecation notice in getopt.1 in a prominent place,
> and uses the same snippet in sh.1 and ksh.1.
> 
> Index: bin/ksh/ksh.1
> ===================================================================
> RCS file: /cvs/src/bin/ksh/ksh.1,v
> retrieving revision 1.214
> diff -u -p -r1.214 ksh.1
> --- bin/ksh/ksh.1     11 Mar 2021 07:04:12 -0000      1.214
> +++ bin/ksh/ksh.1     30 Apr 2021 14:40:52 -0000
> @@ -3219,6 +3219,25 @@ resetting
>  .Ev OPTIND ,
>  may lead to unexpected results.
>  .Pp
> +The following code fragment shows how one might process the arguments
> +for a command that can take the option
> +.Fl a
> +and the option
> +.Fl o ,
> +which requires an argument.
> +.Bd -literal -offset indent
> +while getopts ao: name
> +do
> +     case $name in
> +     a)      flag=1 ;;
> +     o)      oarg=$OPTARG ;;
> +     ?)      echo "Usage: ..."; exit 2 ;;
> +     esac
> +done
> +shift $(($OPTIND - 1))
> +echo "Non-option arguments: " "$@"
> +.Ed
> +.Pp
>  .It Xo
>  .Ic hash
>  .Op Fl r
> Index: bin/ksh/sh.1
> ===================================================================
> RCS file: /cvs/src/bin/ksh/sh.1,v
> retrieving revision 1.152
> diff -u -p -r1.152 sh.1
> --- bin/ksh/sh.1      22 May 2019 15:23:23 -0000      1.152
> +++ bin/ksh/sh.1      30 Apr 2021 14:45:22 -0000
> @@ -508,6 +508,25 @@ is a colon,
>  .Ev OPTARG
>  is set to the unsupported option,
>  otherwise an error message is displayed.
> +.Pp
> +The following code fragment shows how one might process the arguments
> +for a command that can take the option
> +.Fl a
> +and the option
> +.Fl o ,
> +which requires an argument.
> +.Bd -literal -offset indent
> +while getopts ao: name
> +do
> +     case $name in
> +     a)      flag=1 ;;
> +     o)      oarg=$OPTARG ;;
> +     ?)      echo "Usage: ..."; exit 2 ;;
> +     esac
> +done
> +shift $(($OPTIND - 1))
> +echo "Non-option arguments: " "$@"
> +.Ed
>  .It Ic hash Op Fl r | Ar utility
>  Add
>  .Ar utility
> Index: usr.bin/getopt/getopt.1
> ===================================================================
> RCS file: /cvs/src/usr.bin/getopt/getopt.1,v
> retrieving revision 1.19
> diff -u -p -r1.19 getopt.1
> --- usr.bin/getopt/getopt.1   16 Mar 2018 16:58:26 -0000      1.19
> +++ usr.bin/getopt/getopt.1   30 Apr 2021 14:25:17 -0000
> @@ -14,6 +14,13 @@
>  .Ar optstring
>  .Va $*
>  .Sh DESCRIPTION
> +The
> +.Nm
> +utility cannot handle option arguments containing whitespace;
> +consider using the standard
> +.Ic getopts
> +shell built-in instead.
> +.Pp
>  .Nm
>  is used to break up options in command lines for easy parsing by
>  shell procedures, and to check for legal options.
> 

Sure, works for me.

Reply via email to