1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#!/usr/bin/env runawk
#use "power_getopt.awk"
#.begin-str help
# power_getopt - program demonstrating a power of power_getopt.awk module
# usage: power_getopt [OPTIONS]
# OPTIONS:
# -h|--help display this screen
# -f|--flag flag
# --long-flag long flag only
# -s short flag only
# =F|--FLAG <value> flag with value
# =-LONG-FLAG <value> long flag with value
# =S <value> short flag with value
# -X short flag
# =Y <value> short flag with value
# -P print ARGC and ARGV
#.end-str
# Very powerful easy for use module for handling options
BEGIN {
if (getarg("P")){
print "ARGC=" ARGC
for (i=1; i < ARGC; ++i){
printf "ARGV [%d]=%s\n", i, ARGV [i]
}
exit (0)
}
print "The following option were applied"
for (i in options){
print "options [" i "]=" options [i]
}
print "f --- " getarg("f")
print "flag --- " getarg("flag")
print "long-flag --- " getarg("long-flag")
print "s --- " getarg("s")
print "F --- " getarg("F", "default1")
print "FLAG --- " getarg("FLAG", "default2")
print "LONG-FLAG --- " getarg("LONG-FLAG", "default3")
print "S --- " getarg("S", "default4")
print "X --- " getarg("X")
print "Y --- " getarg("Y", "default5")
exit 0
}
|