意外标记附近出现 bash 语法错误

意外标记附近出现 bash 语法错误

我放了一个脚本,当 /etc/profile.d 上有新的 ssh 连接通过 telegram 时,它会提醒我。但是当我连接时,它说:语法错误,附近有意外的标记,问题是什么?我的代码:

#!/usr/bin/env bash
# Import credentials form config file
. /home/roots/credentials.config
URL="https://api.telegram.org/bot${KEY}/sendMessage"
DATE="$(date "+%d %b %Y %H:%M")"
if [ -n "$SSH_CLIENT" ]; then
ip="$(echo $SSH_CONNECTION | cut -d " " -f 1)"
coinfo=($(curl ipinfo.io/${ip}/country))
rinfo=($(curl ipinfo.io/${ip}/region))
cinfo=($(curl ipinfo.io/${ip}/city))"
tinfo=($(curl ipinfo.io/${ip}/timezone))
TEXT="New login via ssh. user name: ${USER}. IP: (*${ip}*)
date: ${DATE}
Approximate location: country ${coinfo}
Region: ${rinfo}
city: ${cinfo}
time zone: ${tinfo}
Note: Location data is approximate."
curl -s -d "chat_id=${USERID}&text=${TEXT}&disable_web_page_preview=true&parse_mode=markdown" $URL > /dev/null
fi

答案1

这个双引号放错了位置。甚至这里的语法高亮器也显示了这一点:

cinfo=($(curl ipinfo.io/${ip}/city))"
#                                   ~

相关内容