Home > Net >  Shell/Bash - extra characters in string variable after assigning cli result
Shell/Bash - extra characters in string variable after assigning cli result

Time:11-03

In one of my variables I store result (string) from aws cli command. When echoing the value it is displayed in " " but injecting it as a parameter shows that extra characters (&#34) are added at the beginning and end of the string.

How to eliminate these? What do they represent?

Code and error log:

dms_arn=$(aws dms describe-replication-tasks --filter Name=replication-task-id,Values="$dms_name" `--query=ReplicationTasks[0].ReplicationTaskArn --region us-east-1)`
echo Stopping Task "$dms_arn"


build   02-Nov-2021 18:52:01    Stopping Task "arn:aws:dms:us-east-1:account:task:XYZ"
error   02-Nov-2021 18:52:02    
error   02-Nov-2021 18:52:02    An error occurred (InvalidParameterValueException) when calling the StopReplicationTask operation: Invalid task ARN:  "arn:aws:dms:us-east-1:account:task:XYZ"

CodePudding user response:

&#34 is the html code for double quote ("). The double quotes are being converted to html code.

Try using the —output text option with your aws command (so you don’t get quotes). See the documentation about output format: https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-output-format.html

If necessary, you can remove wrapping double quotes using shell parameter expansion:

dms_arn=${dms_arn%\"}
dms_arn=${dms_arn#\"}

echo "$dms_arn"
# quotes are gone

CodePudding user response:

&#34 is the HTML entity corresponding to the double quotation marks.

See: entity

To convert them check: Short way to escape HTML in Bash? and Bash script to convert from HTML entities to characters

  • Related