gpt4 book ai didi

linux - Bash(对 base 而言值(value)太大)

转载 作者:太空狗 更新时间:2023-10-29 11:35:30 26 4
gpt4 key购买 nike

我正在修改我在互联网上找到的一些东西来自定义我的 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")

最佳答案

正如你在错误信息中看到的,你在totalSpacefreeSpace的值中得到单位(M),当你只是拉从 df 中提取列。

将这些行更改为

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 输出中的所有 M。

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

关于linux - Bash(对 base 而言值(value)太大),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46042019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com