I am getting the below error while executing a shell script: (Bash)An error occurred (InvalidID) when calling the CreateTags operation: The ID { is not validso when I look in to the shell script there are two lines of the script which is causing the problem, what i find is the output of Line 1 is used as a input of Line 2 (--resource $remote_snapshot_id) in my case:Line 1:remote_snapshot_id=$(aws ec2 copy-snapshot --region us-east-1 --source-region $region --source-snapshot-id $snapshot_id --description $snapshot_id)Line 2:aws ec2 create-tags --region us-east-1 --resource $remote_snapshot_id --tags Key=CreatedBy,Value=AutomatedBackupWhen I try to execute Line 1, as a single command in Linux Terminal:aws --region us-east-1 ec2 copy-snapshot --source-region us-west-1 --source-snapshot-id snap-00220030300040 --description Automated_Backup_425Output:{    SnapshotId: snap-00880090900090}But the Line 2 only require the value snap-00880090900090 from Line 1 Output. (as it is currently picking entire out put starting from { it is giving such error as it only require snap-00880090900090)So my question is how can i grep snap-00880090900090 & store that output to feed for Line 2 (--resource $remote_snapshot_id)can any one help to fix this please?
Shell Script Error - Unable to feed output from one variable to another variable
shell script;scripting
How can I grep snap-00880090900090 [from { SnapshotId: snap-00880090900090 }]?Since the format you intend to extract from is JSON, this is bestaccomplished using JSON-aware tools. I would recommend jq if you canget it installed:command | jq -r .SnapshotIdIf command outputs the JSON snippet you mentioned, then the jqcommand will output just snap-00880090900090 (without quotes, orraw, thanks to option -r).If you cannot install a proper JSON-aware tool, can live with a morefragile solution, and know that the snaphot ID will always have theform shown in your example (snap- followed by a sequence of digits),then you can extract it like this, using GNU grep:command | grep -o 'snap-[0-9]\+'