加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – bash脚本中的'((10#$H> 5))’是什么意思?

发布时间:2020-12-14 01:28:55 所属栏目:Linux 来源:网络整理
导读:我对以下代码片段感到困惑: #!/bin/bashH=$(date +%H); if (( 10#$H 5 ))then # do somethingelse # do something elsefi ((10#$H 5))上面的代码片段是什么意思? 解决方法 10#$H表示使用基数10扩展数字. 这可能是为了从日期中删除任何前导零,因为bash将解
我对以下代码片段感到困惑:

#!/bin/bash

H=$(date +%H); 
if (( 10#$H > 5 ))
then 
        # do something
else 
        # do something else
fi

((10#$H> 5))上面的代码片段是什么意思?

解决方法

10#$H表示使用基数10扩展数字.

这可能是为了从日期中删除任何前导零,因为bash将解释基数8(八进制)中的数字.

例:

$echo "$(( 08 < 5 ))"
bash: 08: value too great for base (error token is "08")

ARITHMETIC EVALUATION: Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise,numbers take the form [base#]n,where base is a decimal number between 2 and 64 representing
the arithmetic base and n is a number in that base. If base# is omitted,then base 10 is used. The digits greater than 9 are represented by the lowercase letters,the uppercase letters,@,and _,in that order. If base is less than or equal to 36,lowercase and uppercase letters may be used interchangeably to represent numbers between 10 and 35.

source: man bash

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读