本文介绍了bash的语法错误:无效的算术运算符与令牌QUOT; @ mail.com"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行SQL SELECT和使用输出发送一些电子邮件的脚本,但与导致该错误消息的脚本的一个问题:

Line 34 is:

if (( ${msgData[$email]:-0} < $(LC_TIME=C date -d yesterday +%s) )); then

Here is the script:

#!/bin/bash
${BASH_VERSION+shopt -s extglob lastpipe} 2>/dev/null

# Full path to a file to store our date offset data. Will be overwritten.
datefile=date.log

# Assign your vars or insert whatever code does so here.
user=user pass=pass db=db

function doit {
    typeset x
    for x; do
        if [[ -z $x ]]; then
            echo 'doit: missing an argument.' >&2
            return 1
        fi
    done

    typeset template=$(</dev/fd/4)
    exec 4<&-
    sqlplus "${1}/${2}@${3}" <&3 | {
        if [[ -f $datefile ]]; then
            . "$datefile" || return 1
        else
            # An associative array that maps from num -> timestamp
            typeset -A msgData
        fi

        # If we've successfully read the file containing timestamps, then overwrite with new data on RETURN
        ${msgData+trap 'trap RETURN; typeset -p msgData >"$datefile"' RETURN}

        while IFS=, read -r num email limit orders; do
            ${email:+:} continue
            if (( ${msgData[$email]:-0} < $(LC_TIME=C date -d yesterday +%s) )); then
                printf -- "$template" "email" "$num" "$limit" "$orders" |
                    /usr/sbin/sendmail -f [email protected] -oi -t

                msgData[$email]=$(LC_TIME=C date +%s)
            else
                printf 'Mail already sent to %s within the last 24 hours... skipping.\n' "$email" >&2
            fi
        done
    }
} 5<&0 <<\SQL 3<&0 <<\TEMPLATE 4<&0 <&5-
set pagesize 0
set feedback 0

SELECT kred_lim.kunr ||','|| kust_adr.ku_email ||','|| kred_lim.kred_limit ||','|| kred_lim.kred_zu_zahlen
FROM kred_lim, kust_adr
WHERE kred_lim.kred_zu_zahlen > kred_lim.kred_limit
AND kred_lim.kunr = kust_adr.ku_nr;
SQL
Subject: Credit limit
To: %s

Customer number: %s
Credit limit: %s
Current orders: %s
TEMPLATE

if ! doit "$user" "$pass" "$db"; then
    echo 'we failed :(' >&2
    exit 1
fi
解决方案

The problem is that you are trying to perform a string comparison inside an arithmetic expression. Either switch to a compound expression:

if [[ ${msgData[$email]:-0} < $(LC_TIME=C date -d yesterday +%s) ]]; then

or check that you are accessing the correct element of msgData.

这篇关于bash的语法错误:无效的算术运算符与令牌QUOT; @ mail.com&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:01