Why are flags often used as modifiers whereas positional parameters are used as targets?
Flags often modify the behavior: it can make a script more or less verbose, or perhaps write the output somewhere. Often, a command manipulates a file, which is then considered the primary target for what the command actually tries to achieve.
Why do we run getopts in a while loop?
All flags are parsed sequentially, and when getopts can no longer find new flags it will return an exit code different from 0, which will exit the while loop at exactly the right moment.
Why do we need a ?) in the case statement?We cannot trust the user to correctly use all flags all the time. ?) matches any flag we have not specified, which we can then use to inform ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.