我有一个shell脚本,其中包含以下命令:
SNAPSHOT_ID=$(bash <<-EOF
aws rds create-db-snapshot
--db-instance-identifier $RDS_INSTANCE_ID
--db-snapshot-identifier $RDS_INSTANCE_ID-manual-$NOW_DATE
--query 'DBSnapshot.[DBSnapshotIdentifier]' --output text
EOF
)但我收到了这个错误:
第191行:寻找匹配`时意外的EOF‘
我怎么才能解决这个问题?
发布于 2019-09-26 15:51:56
您不需要使用here-doc将命令发送到新的shell (您已经在子shell中了):
snapshot_id=$(aws rds create-db-snapshot \
--db-instance-identifier "$RDS_INSTANCE_ID" \
--db-snapshot-identifier "$RDS_INSTANCE_ID-manual-$NOW_DATE" \
--query 'DBSnapshot.[DBSnapshotIdentifier]' --output text)不过,你得避开你的新台词。
我还在参数展开前后添加了引号,并降低了正在创建的一个变量,因为大写变量名是为shell和实用程序保留的(参见POSIX规范,第四段)。
发布于 2019-09-26 15:47:57
我不确定这是否是您的情况,但是如果第二个EOF没有从第一行(第1列)开始,您将得到这样一个错误。例如:
[root@tsekmanrhel771 ~]# cat eoftest.sh
#!/bin/sh
SNAPSHOT_ID=$(bash <<-EOF
aws rds create-db-snapshot
--db-instance-identifier $RDS_INSTANCE_ID
--db-snapshot-identifier $RDS_INSTANCE_ID-manual-$NOW_DATE
--query 'DBSnapshot.[DBSnapshotIdentifier]' --output text
EOF
)
[root@tsekmanrhel771 ~]# ./eoftest.sh
./eoftest.sh: line 3: unexpected EOF while looking for matching `)'
./eoftest.sh: line 10: syntax error: unexpected end of file发布于 2019-09-26 15:48:05
SNAPSHOT_ID=$(bash <<EOF
aws rds create-db-snapshot --db-instance-identifier $RDS_INSTANCE_ID --db-snapshot-identifier $RDS_INSTANCE_ID-manual-$NOW_DATE --query 'DBSnapshot.[DBSnapshotIdentifier]' --output text
EOF
)问题是在EOF之前的"-“和最后的")”似乎是严重的证据,不确定是否来自复制/粘贴。如果需要在新的行中插入命令,请尝试使用"\n“来完成这些命令。
https://stackoverflow.com/questions/58120225
复制相似问题