错误值对于bash中的base太大

错误值对于bash中的base太大,bash,Bash,下面编写的bash脚本用于查找在最后T秒内使用修改的文件,其中T由命令行提供 if [ $# -ne 1 ]; then echo "Wrong number of argument" exit 1 fi for f in * do if [ -x "$f" ]; then currenttime=$(date | awk '{print $4}') modify=$(date -r "$f" | awk '{print $4}')

下面编写的bash脚本用于查找在最后T秒内使用修改的文件,其中T由命令行提供

if [ $# -ne 1 ]; then
    echo "Wrong number of argument"
    exit 1
fi

for f in *
do
    if [ -x "$f" ]; then
        currenttime=$(date | awk '{print $4}')
        modify=$(date -r "$f" | awk '{print $4}')
        d_c=${currenttime:0:2}
        m_c=${currenttime:3:2}
        s_c=${currenttime:6:2}
        d_m=${modify:0:2}
        m_m=${modify:3:2}
        s_m=${modify:6:2}
        let "1d_c *= 24"
        let "m_c *= 60"
        let "second_c = d_c+m_c+s_c"
            let "d_m *= 24"
        let "m_m *= 60"
        let "second_m=d_m+m_m+s_m"
        let "diff=second_c-second_m"
        if [ $diff -lt $1 ]; then
            echo $f
        fi
    fi
do
东北

但我得到了下面的错误

./recent.sh: line 46: let: 09: value too great for base (error token is "09")
./recent.sh: line 47: let: 09: value too great for base (error token is "09")
./recent.sh: line 49: let: 09: value too great for base (error token is "09")

我知道这个错误是由于变量中的大值造成的,我必须将变量设为十进制,但我不知道在我的情况下如何做(在let命令中,如何将它们设为十进制)。

问题是,由于前导的
0
,导致
09
被解释为八进制,而(正如您所猜测的)您需要将其解释为十进制

要解决这个问题,您需要绕过
将变量正常转换为数字的过程。例如,以下内容代替了书写:

let "second_c = d_c+m_c+s_c"
你应该这样写:

let "second_c = 10#$d_c + 10#$m_c + 10#$s_c"
通过预加
$
,您要求Bash将变量值替换为字符串-例如,如果
duc
09
,那么
10#$duc
将是
10#09
10 35;
前缀告诉
let
该数字应解释为基数为10


实际上,仔细想想,当您最初填充这些变量时,最好这样做;例如:

d#c=$((10#${currenttime:0:2}))

这样你就不必在你使用它们的任何地方都这样做。(而且,它使任何错误更接近它们的源代码,从而使调试更容易。)

让“1d_c*=”24“
让“m_c*=”60”
中有一些错误的双引号,这完全破坏了Bash语法。请确认您在此发布的代码是正确的,并生成您声称的错误。(提示:没有。您的错误消息指的是第46、47和49行,但您只发布了28行代码。请修复。)
让“1d_c*=”24“
?您缺少一个
字符,但我相信您不需要任何
字符。还可以阅读bash中提供的算术处理,即
((m*=60));echo“$m_m
。另外,当bash认为它在八进制值(即00-08,所以09)上运行时,会出现错误。祝你好运。你能告诉我解决办法吗。。。。如何解决这个问题