【发布时间】:2022-04-20 21:29:54
【问题描述】:
从命令行获取代码的 1 条线可以正常工作,但我在脚本中运行时遇到此错误。
我运行从命令行获取 TICKERD 的 1 班轮,这不会给我错误。
但是,我相信是因为数组中的数据为空?
curl -k -s https://api.earningscalendar.net/?date=20190518
[]
#!/bin/bash
for i in {1..15}
do
newdate=`/bin/date -v +"$i"d +%Y%m%d`
TICKERD=`curl -k -s https://api.earningscalendar.net/?date=$newdate | jq -r 'map([.ticker, .when] | join(", ")) | join("\n")' | grep -w "$1"`
TICKERA=`echo $TICKERD | cut -d, -f1`
if [ "$TICKERA" == "$1" ]
then
echo $TICKERD "is on" $newdate
exit
fi
done
错误信息:
./earnings.sh ADSK
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
parse error: Invalid numeric literal at line 1, column 6
ADSK, amc is on 20190523
【问题讨论】:
-
也许你应该看看你得到什么作为回应?一旦你计算了那个日期,你可能会得到一些不是 json 的东西。
newdate变量也是如此。