1

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"
marcin2x4
  • 1,321
  • 2
  • 18
  • 44
  • 1
    [They represent quotes.](https://www.codetable.net/decimal/34) So you need to figure out what is generating and escaping them and why. It looks like the output is meant for a browser or the like. – Andrej Podzimek Nov 02 '21 at 23:06
  • BTW, if you want to just trim 5 leading and 5 trailing characters from a string, that would be `dms_arn='"arn:aws:dms:us-east-1:account:task:XYZ"'; echo "${dms_arn:5:-5}"`. – Andrej Podzimek Nov 02 '21 at 23:12
  • 1
    It's a denotation of [HTML entities](https://www.w3schools.com/html/html_entities.asp). – user1934428 Nov 03 '21 at 07:26

2 Answers2

3

&#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
dan
  • 4,846
  • 6
  • 15
2

&#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

user2314737
  • 27,088
  • 20
  • 102
  • 114