bash试图将变量传入curl命令

bash试图将变量传入curl命令,bash,curl,Bash,Curl,我试图在curl命令中使用变量,我得到以下两种结果之一: test.sh第32行:查找匹配项时出现意外EOF test.sh第33行:语法错误:文件意外结束 “$key” 我的命令是: curl 'http://1.1.1.1:8080/v2-beta/projects/1a25/stack' -H 'content-type: application/json' -data-binary $'{"system":true,"type":"stack","name":"ecr","startOn

我试图在curl命令中使用变量,我得到以下两种结果之一:

  • test.sh第32行:查找匹配项时出现意外EOF

    test.sh第33行:语法错误:文件意外结束

  • “$key”
  • 我的命令是:

    curl 'http://1.1.1.1:8080/v2-beta/projects/1a25/stack' -H 'content-type: application/json' -data-binary $'{"system":true,"type":"stack","name":"ecr","startOnCreate":true,"environment":{"key_id":"$key","access_key":"214356","aws_region":"ap-southeast-2","auto_create":"false","log_level":"INFO","registry_in_which_environment":"current","environment_api_endpoint":"12345.dkr.amazonaws.com","environment_api_access_key":"7AC2D3FE5A1C12345","environment_api_secret_key":"QMmwp7ebmzK1ZcUCjoRM12345"},"dockerCompose":"ecr-updater:\\n  environment:\\n    AWS_ACCESS_KEY_ID: ${aws_access_key_id}\\n    AWS_SECRET_ACCESS_KEY: ${aws_secret_access_key}\\n    AWS_REGION: ${aws_region}\\n    AUTO_CREATE: ${auto_create}\\n    LOG_LEVEL: ${log_level}\\n    {{- if eq .Values.registry_in_which_environment \\"other\\" }}\\n    CATTLE_URL: ${environment_api_endpoint}\\n    CATTLE_ACCESS_KEY: ${environment_api_access_key}\\n    CATTLE_SECRET_KEY: ${environment_api_secret_key}\\n    {{- end }}\\n  labels:\\n    io.rancher.container.pull_image: always\\n    {{- if eq .Values.registry_in_which_environment \\"current\\" }}\\n    io.rancher.container.create_agent: \'true\'\\n    io.rancher.container.agent.role: environment\\n    {{- end }}\\n  tty: true\\n  image: rancher/rancher-ecr-credentials:v2.0.1\\n  stdin_open: true\\n","rancherCompose":".catalog:\\n  name: \\"ECR Credential Updater\\"\\n  version: \\"v2.0.1\\"\\n  description: \\"Updates credentials for ECR in Rancher\\"\\n  minimum_rancher_version: \\"v1.6.13-rc1\\"\\n  questions:\\n    - variable: \\"aws_access_key_id\\"\\n      label: \\"AWS Access Key ID\\"\\n      description: \\"AWS API Access Key to use for obtaining ECR credentials. Not required if using IAM roles.\\"\\n      required: false\\n      type: \\"string\\"\\n    - variable: \\"aws_secret_access_key\\"\\n      label: \\"AWS Secret Access Key\\"\\n      description: \\"AWS API Secret Key to use for obtaining ECR credentials. Not required if using IAM roles.\\"\\n      required: false\\n      type: \\"string\\"\\n    - variable: \\"aws_region\\"\\n      label: \\"AWS Region\\"\\n      description: \\"AWS Region that hosts the ECR\\"\\n      default: us-east-1\\n      required: true\\n      type: \\"string\\"\\n    - variable: \\"auto_create\\"\\n      label: \\"Auto Create\\"\\n      description: \\"Automatically create registry in Rancher for corresponding ECR repo if it doesn\'t already exist\\"\\n      default: \\"false\\"\\n      required: true\\n      type: \\"string\\"\\n    - variable: \\"log_level\\"\\n      label: \\"Log Level\\"\\n      description: \\"Logging level to run service at\\"\\n      default: \\"INFO\\"\\n      required: true\\n      type: \\"string\\"\\n    - variable: \\"registry_in_which_environment\\"\\n      type: enum\\n      label: \\"Registry Environment\\"\\n      description: \\"Which environment is the AWS registry located?\\"\\n      default: current\\n      options:\\n        - current\\n        - other\\n    - variable: \\"environment_api_endpoint\\"\\n      label: \\"URL (Environment API Endpoint) of Registry to be Updated\\"\\n      description: \\"URL for where the registry is located. This is the endpoint, which can be found under the Advanced Options under API -> Keys, for an Environment API Key.\\"\\n      default: \\"\\"\\n      required: false\\n      type: \\"string\\"\\n    - variable: \\"environment_api_access_key\\"\\n      label: \\"Access Key of an Environment API Key\\"\\n      description: \\"This access key must be for the environment where the registry will need to be updated. This access key will be created in the same environment listed for the URL. This can be created in the Advanced Options under API.\\"\\n      default: \\"\\"\\n      required: false\\n      type: \\"string\\"\\n    - variable: \\"environment_api_secret_key\\"\\n      label: \\"Secret Key of an Environment API Key\\"\\n      description: \\"This secret key must be for the environment where the registry will need to be updated. This secret key will be created in the same environment listed for the URL. This can be created in the Advanced Options under API.\\"\\n      default: \\"\\"\\n      required: false\\n      type: \\"string\\"\\necr-updater:\\n  scale: 1\\n","externalId":"catalog://library:infra*ecr:1"}'
    

    在以下示例中,您将看到两个工作变量:

  • $backup\u不带双引号的哈希

  • $index,在JSON中包含双引号

  • curl-k-XPOST'somesite/\u snapshot/cs automated/'$backup\u hash'/\u restore'-d'{“index”:““$index”''''}'-H”内容类型:application/json'

    使用带有语法突出显示的编辑器以确保代码未被破坏:


    (1)向我们显示您实际使用的命令。现在的问题不会生成您显示的消息。(2)当您需要有关错误消息的帮助时,请始终提供完整的错误消息,而不仅仅是您认为重要的部分。抱歉,这仍然是全新的。添加了完整的curl命令变量引用(例如
    $key
    )不要在
    $”…“
    中展开,
    curl
    没有可请求的URL;您只有一个巨大的JSON blob,它通常是
    -d
    选项的参数。