簡體   English   中英

bash 試圖將變量傳遞給 curl 命令

[英]bash trying to pass in a variable into curl command

我試圖在 curl 命令中使用變量,我要么得到以下兩個之一:

  1. test.sh 第 32 行:在尋找匹配`"'時出現意外的 EOF

    test.sh 第 33 行:語法錯誤:文件意外結束

  2. "$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"}'

在以下 curl 中,您將看到兩個工作變量:

  1. $backup_hash 不帶雙引號

  2. $index 在 JSON 中帶有雙引號

curl -k -XPOST 'somesite/_snapshot/cs-automated/'"$backup_hash"'/_restore' -d '{"indices": "'"$index"'"}' -H 'Content-Type: application/json'

使用帶有語法高亮的編輯器來確保你的代碼沒有被破壞:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM