【问题标题】:Bash (value too great for base)Bash(对于基础来说价值太大)
【发布时间】:2017-09-05 03:48:58
【问题描述】:

我正在修改我在互联网上找到的一些东西来自定义我的 pi ssh 登录消息,但我最终遇到了错误。

以下是我的代码:

let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`

let totalSpace="$(df -Bm | grep /dev/root | awk {'print $4'})"
let freeSpace="$(df -Bm | grep /dev/root | awk {'print $3'})"
TOTAL=`echo "$freeSpace Mb (Free) / $totalSpace (Total)"`

# get the load averages
read one five fifteen rest < /proc/loadavg

echo "$(tput setaf 2)
   .~~.   .~~.    `date +"%A, %e %B %Y, %r"`
  '. \ ' ' / .'   `uname -srmo`$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :   Uptime.............: ${UPTIME}
 ~ (   ) (   ) ~  Memory.............: ${TOTAL}
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  )
   '~ .~~~. ~'
       '~'
$(tput sgr0)"

它返回这些错误,我不知道如何解决它们:

/home/pi/.bash_profile: line 8: let: totalSpace=12688M: value too great for base (error token is "12688M")
/home/pi/.bash_profile: line 9: let: freeSpace=1562M: value too great for base (error token is "1562M")

【问题讨论】:

    标签: linux bash


    【解决方案1】:

    正如您在错误消息中看到的,当您从df 中拉出列时,您会在totalSpacefreeSpace 的值中获得单位(M)。

    将这些行更改为

    totalSpace="$(df -Bm | tr -d 'M' | grep /dev/root | awk {'print $4'})"
    freeSpace="$(df -Bm | tr -d 'M' | grep /dev/root | awk {'print $3'})"
    

    这将删除 df 输出中的所有 Ms。

    也删除所有lets。它们很古老,不需要。

    【讨论】:

    • 非常感谢您的帮助。
    • 并通过让awk 匹配/dev/root(即...tr -d 'M' | awk '/\/dev\/root/{print $4}')来消除额外的过程......祝你好运。
    • @PaulSerander 实际上,df 可以取一个目录名并只为您提供其分区的信息......就像在df -Bm / 中一样。
    • @Kusalananda :是的 df 可以接受一个参数,但它仍然会产生一个标题。使用awk /\/dev\/root/{print $4}' 解决方案会自动忽略标题。祝大家好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2014-03-12
    相关资源
    最近更新 更多