麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 開(kāi)發(fā) > Linux Shell > 正文

shell腳本nicenumber實(shí)現(xiàn)代碼

2020-07-27 19:01:35
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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 is echoed to stdout.

廢話不多說(shuō),首先是

#!/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 is echoed to stdout.nicenumber(){ # Note that we assume that '.' is the decimal separator in # the INPUT value to this script. The decimal separator in the output value is # '.' unless specified by the user with the -d flag integer=$(echo $1 | cut -d. -f1)       # left of the decimal decimal=$(echo $1 | cut -d. -f2)       # right of the decimal if [ $decimal != $1 ]; then  # There's 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 remainder, if any  result="${TD:=","}${remainder}${result}"  # builds right to left done nicenum="${thousands}${result}" if [ ! -z $2 ] ; then  echo $nicenum fi}DD="." # decimal point delimiter, to separate integer and fractional valuesTD="," # thousands delimiter, to separate every three digitswhile getopts "d:t:" opt; do case $opt in  d ) DD="$OPTARG"  ;;  t ) TD="$OPTARG"  ;; esacdoneshift $(($OPTIND - 1))if [ $# -eq 0 ] ; then echo "Usage: $(basename $0) [-d c] [-t c] numeric value" echo " -d specifies the decimal point delimiter (default '.')" echo " -t specifies the thousands delimiter (default ',')" exit 0finicenumber $1 1     # second arg forces nicenumber to 'echo' outputexit 0

這腳本我們以后分析,現(xiàn)在先mark下。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 免费在线成人网 | 亚洲免费观看视频 | 国产女同玩人妖 | 欧美在线观看视频一区二区 | 久久中文免费 | a免费毛片| 国产人成精品一区二区三 | 最新黄色电影网站 | www.99tv| 小视频在线看 | 久久噜噜噜 | 久久精品国产99久久久古代 | 91精品国产一区二区在线观看 | 99亚洲国产精品 | 国产91久久久久久 | 久久草草影视免费网 | 欧美精品v国产精品v日韩精品 | 国产91porn| 在线播放免费人成毛片乱码 | 2019天天干夜夜操 | 黄色网址电影 | 国产一区二区久久精品 | 欧美日韩在线播放 | 国产精品视频成人 | 伊人一二三四区 | 欧美一区二区网站 | 看中国一级毛片 | 91精品国产91久久久久久不卞 | 色999中文字幕 | 国产精品视频一区二区噜噜 | 欧美1区2区在线观看 | 久久2019中文字幕 | 国产精品麻豆91 | 欧美国产第一页 | 精品久久久久久成人av | 免费a级网站 | 性大片免费看 | 成码无人av片在线观看网站 | 成人性视频在线 | av电影免费看 | 欧美视频首页 |