xargs 没有从 aws cli 输出中拆分空格
xargs not splitting on whitespace from aws cli output
此命令 returns 所有由空格分隔的 AWS 区域:
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text
eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2
我正在尝试将其通过管道传输到 xargs,但它会将其视为单个字符串:
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text | gxargs -I {} aws cloudformation list-stacks --region {}
Invalid endpoint: https://cloudformation.eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2.amazonaws.com
gxargs: aws: exited with status 255; aborting
gxargs 就是 gnu xargs(我在 Mac)。
此外,尝试使用 jmespath 从具有特定分隔符的数组创建字符串(我可以将其与 xargs 一起使用):
aws ec2 describe-regions --query 'Regions[*].join(",",@.RegionName)'
In function join(), invalid type for value: None, expected one of: ['string'], received: "null"
编辑:只是跟进,这就是我的结局。它坚持在找不到堆栈时抛出错误 - 其他 aws cli 命令可能相同
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text | gxargs -n 1 sh -c 'aws cloudformation describe-stacks --stack-name findme --region [=13=] || true'
-I
的man xargs
:
-I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks
do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.
您可以改用xargs -n 1 aws cloudformation list-stacks --region
此命令 returns 所有由空格分隔的 AWS 区域:
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text
eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2
我正在尝试将其通过管道传输到 xargs,但它会将其视为单个字符串:
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text | gxargs -I {} aws cloudformation list-stacks --region {}
Invalid endpoint: https://cloudformation.eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2.amazonaws.com
gxargs: aws: exited with status 255; aborting
gxargs 就是 gnu xargs(我在 Mac)。
此外,尝试使用 jmespath 从具有特定分隔符的数组创建字符串(我可以将其与 xargs 一起使用):
aws ec2 describe-regions --query 'Regions[*].join(",",@.RegionName)'
In function join(), invalid type for value: None, expected one of: ['string'], received: "null"
编辑:只是跟进,这就是我的结局。它坚持在找不到堆栈时抛出错误 - 其他 aws cli 命令可能相同
aws ec2 describe-regions --query 'Regions[*].RegionName' --output text | gxargs -n 1 sh -c 'aws cloudformation describe-stacks --stack-name findme --region [=13=] || true'
-I
的man xargs
:
-I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.
您可以改用xargs -n 1 aws cloudformation list-stacks --region