User Tools

Site Tools


posix_shell_getpots

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
posix_shell_getpots [2019/09/30 11:02]
rpjday [Starting points]
posix_shell_getpots [2019/09/30 11:04]
rpjday [Starting points]
Line 13: Line 13:
 First, there has been much blood spilled discussing how to support //​optional//​ arguments using ''​getopts''​ -- the correct solution is to not do that, as explained in Guideline 7 [[https://​pubs.opengroup.org/​onlinepubs/​9699919799/​basedefs/​V1_chap12.html#​tag_12_02|here]]. So we won't. First, there has been much blood spilled discussing how to support //​optional//​ arguments using ''​getopts''​ -- the correct solution is to not do that, as explained in Guideline 7 [[https://​pubs.opengroup.org/​onlinepubs/​9699919799/​basedefs/​V1_chap12.html#​tag_12_02|here]]. So we won't.
  
-And, second, if the //​optstring//​ handed to getopts starts with a colon, then getopts uses what is called "​silent error reporting";​ this appears to be the recommended approach, so we'll stick with that. If you choose differentlyyou're on your own.+And, second, if the //​optstring//​ handed to getopts starts with a colon, then getopts uses what is called "​silent error reporting";​ this appears to be the recommended approach, so we'll stick with that. In shortdon't do this: 
 + 
 +<​code>​ 
 +while getopts ab:c: opt ; do 
 +</​code>​ 
 + 
 +Do this (note the leading colon): 
 + 
 +<​code>​ 
 +while getopts :ab:c: opt ; do 
 +</​code>​ 
 + 
 +Explanation below.
posix_shell_getpots.txt · Last modified: 2019/09/30 12:16 by rpjday