Linux 在shell脚本中查找匹配的“)”时出现意外EOF
我有一个shell脚本,其中包含以下命令:Linux 在shell脚本中查找匹配的“)”时出现意外EOF,linux,bash,shell,unix,Linux,Bash,Shell,Unix,我有一个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 --quer
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
如何修复此问题?我不确定这是否是您的情况,但如果第二个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
问题在于EOF之前的和最后一个似乎识别错误,不确定是否来自复制/粘贴。尝试一下,如果命令需要插入到新行中,请使用\n完成这些命令。将命令发送到新shell时不需要here doc,而且您已经在子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和实用程序保留的。请参见第四段。-之前EOF是一个用于修剪前导制表符缩进的Bash功能。你说得对,我错了,尽管调整EOF和上一个EOF对我有点作用。我在我的盒子里使用了一个随机命令。你能检查一下你的文件吗?这个命令在一个shell脚本中。可以使用您的解决方案吗?@user1297406可以。这是在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)