getopt_silent.tests 1.2 KB

1234567891011121314151617181920212223
  1. # Open Group Base Specifications Issue 7:
  2. # """
  3. # If an unknown option is met, VAR shall be set to "?". In this case,
  4. # if the first character in optstring is ":", OPTARG shall be set
  5. # to the option character found, but no output shall be written
  6. # to standard error; otherwise, the shell variable OPTARG shall be
  7. # unset and a diagnostic message shall be written to standard error."
  8. # ...
  9. # If an option-argument is missing:
  10. # If the first character of optstring is ":", VAR shall be set to ":"
  11. # and OPTARG shall be set to the option character found.
  12. # """
  13. echo "*** optstring:':ac' args:-a -b -c"
  14. getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  15. getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  16. getopts ":ac" var -a -b -c; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  17. getopts ":ac" var -a -b -c; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  18. # Previous line should result in "rc:1", which is normally treated
  19. # in getopts loops as exit condition.
  20. # Nevertheless, let's verify that calling it yet another time doesn't do
  21. # anything weird:
  22. getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"