在 Windows cmd 提示符下写一个 *nix 命令

Write a *nix command on Windows cmd prompt

我正在尝试执行在命令提示符 here 上找到的 *nix 命令:

vault write aws/roles/my-role \
        credential_type=iam_user \
        policy_document=-<<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1426528957000",
      "Effect": "Allow",
      "Action": [
        "ec2:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
EOF

到目前为止,我已经尝试了不同的方法 combinations/variations,例如将命令写在一行中,例如:

C:\Users\user-name>vault write aws/roles/my-role credential_type=iam_user policy_document={"Version": "2012-10-17","Statement": [{"Sid": "Stmt1426528957000","Effect": "Allow","Action": ["ec2:*"],"Resource": ["*"]}]}
Failed to parse K=V data: invalid key/value pair "2012-10-17,Statement:": format must be key=value

或像这样的多行:

C:\Users\user-name>vault write aws/roles/my-role ^
More? credential_type=iam_user ^
More? policy_document=-^<^<EOF ^
More? { ^
More? ^"Version^" : ^"2012-10-17^", ^
More? ^"Statement^" : [ ^
More? { ^
More? ^"Sid^" : ^"Stmt1426528957000^", ^
More? ^"Effect^" : ^"Allow^", ^
More? ^"Action^" : [ ^
More? ^"ec2:*^" ^
More? ], ^
More? ^"Resource^": [ ^
More? ^"*^" ^
More? ] ^
More? } ^
More? ] ^
More? } ^
More? EOF
Failed to parse K=V data: invalid key/value pair "{": format must be key=value

注意 1:它适用于 Git Bash,我只是好奇如何让它在 cmd 提示符下工作。

注2:

C:\Users\user-name>where vault
C:\ProgramData\chocolatey\bin\vault.exe

$ which vault
/c/ProgramData/chocolatey/bin/vault

在 cmd 中这似乎有效:

vault write aws/roles/test-role credential_type=iam_user policy_document={\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Stmt1426528957000\",\"Effect\":\"Allow\",\"Action\":[\"ec2:*\"],\"Resource\":[\"*\"]}]}

成功!数据写入:aws/roles/test-role

我删除了 json 中的空格,转义了每个双引号字符并将所有内容放在一行中。