Bash
getopts in Bash: Parse Command-Line Options Properly
A tested getopts skeleton for Bash scripts: flags, options with values, required options, error handling, and a manual loop for --long options.
Topic
A tested getopts skeleton for Bash scripts: flags, options with values, required options, error handling, and a manual loop for --long options.
while IFS= read -r line is the correct loop, but the last line, pipes, commands that read stdin and Windows line endings each have a trap. Here they are, tested.
A yes/no confirmation prompt for Bash scripts that accepts any case, has an optional default and handles cron, pipes and EOF without looping forever.
Check that input is a whole number, a signed integer or a decimal before doing arithmetic, and avoid the octal, empty-string and injection problems in (( )).