Running example.tcl with the --help option produces the following output:

Usage: tac.tcl [OPTION]... [FILE]...
Write each FILE to standard output, last line first.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -b, --before            attach the separator before instead of after
  -r, --regex             interpret the separator as a regular expression
  -s, --separator=STRING  use STRING as the separator instead of newline
  -h, -?, --help          display this help and exit
      --version           output version information and exit

Allowing option values to be changed between arguments can also easily be achieved by calling getopt in a loop:

while {[llength $argv] > 0} {
    getopt arg $argv {
        -x: - --optionx: {
            set optionx $arg
        }
        arglist {
            if {[llength $arg] == 0} {error "missing file"}
            set argv [lassign $arg file]
        }
    }
    set argv [lassign $arg file]
    process $file
}

If called with: '--optionx 42 file1 file2 -x99 file3', this would process files file1 and file2 with optionx set to 42 and file3 with optionx set to 99. But using: '-x 42 file1 -x 88' would produce a usage message because the file to be processed with the last value of optionx is missing.
