Given A number, shows it in comma-separated form. expects DD and TD to is instantiated. Instantiates Nicenum. Or, if a second arg is specified, the output was echoed to stdout.
Nonsense not much to say that the first is
#!/bin/sh # Nicenumber-Given A number, shows it in comma-separated form. # expects DD and TD to be instantiated.
Instantiates Nicenum # or, if a second arg is specified, the output was echoed to stdout. Nicenumber () {# Note-we assume that '. ' Are the decimal separator in # The INPUT value to this script. The decimal separator in the output value was # '. ' unless specified by the user with The-d flag integer=$ (echo $ | cu T-d-f1) # Left of the decimal decimal=$ (Echo | cut-d.-f2) # Right of the decimal if [$decimal!= $ 1];
Then # There ' a fractional part, so let ' s include it. result= "${dd:=". "} $decimal "fi thousands= $integer while [$thousands-gt 999]; Do remainder=$ (($thousands% 1000)) # Three least significant digits while [${#remainder}-lt 3]; Do # force leading zeros as needed remainder= ' 0$remainder ' Done thousands=$ (($thousands/1000)) # to left of REM Ainder, if any result= "${td:=", "}${remainder}${result}" #Builds right to left do nicenum= "${thousands}${result}" if [!-Z $]; Then echo $nicenum fi} dd= "." # decimal point delimiter, to separate integer and fractional values td= "," # thousands Delimiter, to separate every three digits while getopts "d:t:" OPT;
Do case $opt in D) dd= "$OPTARG"
T) td= "$OPTARG";; ESAC Done Shift $ (($OPTIND-1)) if [$#-eq 0]; Then echo "Usage: $ (basename $) [D-C] [-t C] numeric value" echo "-d specifies the decimal point delimiter (default)
.')" echo "-t specifies the thousands delimiter (default ', ')" Exit 0 fi Nicenumber $1 # second ARG forces To ' echo ' output exit 0
This script we'll analyze later, Mark now.