bash的语法错误:无效的算术运算符与令牌QUOT; @ mail.com" [英] bash syntax error: invalid arithmetic operator with token "@mail.com"
本文介绍了bash的语法错误:无效的算术运算符与令牌QUOT; @ mail.com"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个执行SQL SELECT和使用输出发送一些电子邮件的脚本,但与导致该错误消息的脚本的一个问题:
第34行:johne@mail.com:语法错误:无效的算术运算符
(错误标记为@ mail.com)
块引用>34号线是:
IF(($ {MSGDATA [$电子邮件]: - 0}< $(LC_TIME = C日期-d昨日+%S)));然后
下面是脚本:
#!/斌/庆典
$ {BASH_VERSION +禁用了javascript -s extglob lastpipe} 2 - ;的/ dev / null的#保存我们的约会全部文件路径偏移数据。将被覆盖。
datefile = date.log#将您的增值经销商或插入的任何code这样做在这里。
用户=用户通=通过DB =分贝DOIT功能{
排版点¯x
对于x;做
如果[[-z $ X]];然后
回声DOIT:缺少一个说法。 >和2
返回1
科幻
DONE 排版模板= $(小于为/ dev / FD / 4)
EXEC 4℃;&放大器; -
SQLPLUS$ {1} / $ {2} @ $ {3}&下;和3 | {
如果[[-f $ datefile]];然后
。 $ datefile||返回1
其他
#关联数组,从NUM地图 - >时间戳
排版-A MSGDATA
科幻 #如果我们已经成功地读取包含时间戳的文件,然后对返回的新数据覆盖
$ {MSGDATA +陷阱陷阱回报;排版-p MSGDATA>中$ datefile'RETURN} 而IFS =读-r NUM电子邮件限价盘;做
$ {电子邮件:+:}继续
如果(($ {MSGDATA [$电子邮件]: - 0}< $(LC_TIME = C日期-d昨日+%S)));然后
printf的 - $模板,电子邮件,$ NUM,$限制$订单|
/ usr / sbin目录/ sendmail的-f sender@example.com -oi -t MSGDATA [$电子邮件= $(LC_TIME = C日期+%S)
其他
printf的邮件已经过去24小时内发送到%s ...跳过\\ n'。$电子邮件>和2
科幻
DONE
}
} 5';&放大器; 0℃;&下; \\ SQL 3';&放大器; 0℃;&下; \\ TEMPLATE 4℃;&放大器; 0℃;&放大器; 5-
设置页面大小0
集反馈0选择kred_lim.kunr ||','|| kust_adr.ku_email ||','|| kred_lim.kred_limit ||','|| kred_lim.kred_zu_zahlen
从kred_lim,kust_adr
WHERE kred_lim.kred_zu_zahlen> kred_lim.kred_limit
和kred_lim.kunr = kust_adr.ku_nr;
SQL
主题:信用额度
为:%s客户编号:%s的
信用额度:%s的
目前订单:%s的
模板如果! DOIT$用户,$传,$ DB;然后
回声我们失败了:('>和2
1号出口
科幻
解决方案的问题是,您要执行算术前pression内字符串比较。更换为复合前pression:
如果[[$ {MSGDATA [$电子邮件]: - 0}< $(LC_TIME = C日期-d昨日+%S)];然后
或检查你正在访问的正确元素
MSGDATA
。I have a script that performs a SQL SELECT and sends some e-mails using the output but there is an issue with the script causing the error message:
line 34: johne@mail.com: syntax error: invalid arithmetic operator (error token is "@mail.com")
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 sender@example.com -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;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文