Bash:查找匹配项时出现意外的EOF
我正在尝试在远程AWS Windows Server 2016数据中心上运行BitBucket管道Bash:查找匹配项时出现意外的EOF,bash,amazon-web-services,yaml,bitbucket,ssm,Bash,Amazon Web Services,Yaml,Bitbucket,Ssm,我正在尝试在远程AWS Windows Server 2016数据中心上运行BitBucket管道 image: python:3.5.1 pipelines: custom: # Pipeline that only runs manually default: - step: caches: - pip script: # Modify the commands below to build your
image: python:3.5.1
pipelines:
custom: # Pipeline that only runs manually
default:
- step:
caches:
- pip
script: # Modify the commands below to build your repository.
- pip install awscli
- <-
aws ssm send-command
--document-name "AWS-RunRemoteScript"
--instance-ids "i-000000000000000"
--parameters '{\"sourceType\":[\"S3\"],\"sourceInfo\":[\'{\"path\":\"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1\"}\'],\"executionTimeout\":[\"3600\"],\"commandLine\":[\"test.ps1\"],\"workingDirectory\":[\"C:\\\\TOM\"]}'
--timeout-seconds 600
--region us-east-2
更新2:
+ aws ssm send-command --document-name "AWS-RunRemoteScript" --instance-ids "i-0000000000000000" --parameters '{\"sourceType\":[\"S3\"],\"sourceInfo\":["{\"path\":\"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1\"}"],\"executionTimeout\":[\"3600\"],\"commandLine\":[\"test.ps1\"],\"workingDirectory\":[\"C:\\\\TOM\"]}' --timeout-seconds 600 --region us-east-2
Error parsing parameter '--parameters': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
JSON received: {\"sourceType\":[\"S3\"],\"sourceInfo\":["{\"path\":\"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1\"}"],\"executionTimeout\":[\"3600\"],\"commandLine\":[\"test.ps1\"],\"workingDirectory\":[\"C:\\\\TOM\"]}
在shell中,在单个带引号的字符串中,反斜杠不会转义任何内容。他们只是普通的角色。此外,只要加上引号,就可以将多个带引号或不带引号的字符串段连接在一起 因此,如果你有:
'abc\'def\'ghi'
你会得到:
- 由四个字符abc\组成的单引号段。第二个's'终止这个带引号的段
- 不带引号的字符def
- 反斜杠转义”(因为反斜杠在单引号段之外转义引号)
- 不带引号的字符ghi
- 最后,出现了一个不匹配的错误消息
--parameters '{"sourceType":["S3"],"sourceInfo":['\''{"path":"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1"}'\''],"executionTimeout":["3600"],"commandLine":["test.ps1"],"workingDirectory":["C:\\\\TOM"]}'
注意使用序列'\'
来:
- 关闭单引号段
- 插入单引号
- 打开一个新的单引号段
“”
但是,我并不完全相信您真的应该引用sourceInfo
参数。如果假定为JSON,则单引号无效,因此sourceInfo
参数的值需要双引号,并且该字符串值内的双引号需要转义:
--parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1\"}"],"executionTimeout":["3600"],"commandLine":["test.ps1"],"workingDirectory":["C:\\\\TOM"]}'
谢谢你的解释和建议。请查看我文章中的更新部分。@technext:是的,这正是我在最后一段中所说的。单引号不是有效的JSON,因此会出现JSON解析错误。我在那一段中也解释了解决方案。@rici:解释得很好;有可能一个heredoc可以用于JSON,这可能会解决转义问题。。。不过我还没有试过。@rici:很抱歉,我只是试了一下你第一次提到的代码块。你能检查一下“更新2”看看我的建议是否正确吗?@Technext:我添加了一个明确的示例,并在最后的文件路径中重新引入了双反斜杠,因为我非常确定JSON解析器将需要这样做。
--parameters '{"sourceType":["S3"],"sourceInfo":['\''{"path":"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1"}'\''],"executionTimeout":["3600"],"commandLine":["test.ps1"],"workingDirectory":["C:\\\\TOM"]}'
--parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://s3.us-east-2.amazonaws.com/my-bucket-name/test.ps1\"}"],"executionTimeout":["3600"],"commandLine":["test.ps1"],"workingDirectory":["C:\\\\TOM"]}'