getopt_silent.tests 1.3 KB

1234567891011121314151617181920212223242526272829
  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. (
  14. echo "*** optstring:':ac' args:-a -b -c"
  15. getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  16. getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  17. getopts ":ac" var -a -b -c; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  18. getopts ":ac" var -a -b -c; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  19. # Previous line should result in "rc:1", which is normally treated
  20. # in getopts loops as exit condition.
  21. # Nevertheless, let's verify that calling it yet another time doesn't do
  22. # anything weird:
  23. getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
  24. ) 2>&1 \
  25. | sed -e 's/ unrecognized option: / invalid option -- /' \
  26. -e 's/ illegal option -- / invalid option -- /' \