Bash-4.2 distribution sources and documentation
[platform/upstream/bash.git] / builtins / getopts.def
index a9aad62..1d2a68a 100644 (file)
@@ -5,26 +5,28 @@ Copyright (C) 1987-2004 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
-Bash is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
-version.
+Bash is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
-Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or
-FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-for more details.
+Bash is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License along
-with Bash; see the file COPYING.  If not, write to the Free Software
-Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
+You should have received a copy of the GNU General Public License
+along with Bash.  If not, see <http://www.gnu.org/licenses/>.
 
 $PRODUCES getopts.c
 
 $BUILTIN getopts
 $FUNCTION getopts_builtin
 $SHORT_DOC getopts optstring name [arg]
-Getopts is used by shell procedures to parse positional parameters.
+Parse option arguments.
+
+Getopts is used by shell procedures to parse positional parameters
+as options.
 
 OPTSTRING contains the option letters to be recognized; if a letter
 is followed by a colon, the option is expected to have an argument,
@@ -54,6 +56,10 @@ OPTSTRING is not a colon.  OPTERR has the value 1 by default.
 
 Getopts normally parses the positional parameters ($0 - $9), but if
 more arguments are given, they are parsed instead.
+
+Exit Status:
+Returns success if an option is found; fails if the end of options is
+encountered or an error occurs.
 $END
 
 #include <config.h>
@@ -102,7 +108,9 @@ getopts_bind_variable (name, value)
   if (legal_identifier (name))
     {
       v = bind_variable (name, value, 0);
-      return (v && (readonly_p (v) == 0)) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
+      if (v && (readonly_p (v) || noassign_p (v)))
+       return (EX_MISCERROR);
+      return (v ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
     }
   else
     {