Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to escape single quote in ARM template

Given the following resource in an AzureRM template, how would one encode the single quote in the commandToExecute part?

{   "type": "Microsoft.Compute/virtualMachines/extensions",   "name": "[concat(variables('vmNameMaster'), copyIndex(), '/sethost')]",   "apiVersion": "2015-06-15",   "location": "[resourceGroup().location]",   "copy": {       "name": "extensionLoopNode",       "count": "[variables('masterCount')]"   },   "dependsOn": [       "[concat('Microsoft.Compute/virtualMachines/', variables('vmNameMaster'), copyIndex(),'/extensions/DockerExtension')]"   ],   "properties": {     "publisher": "Microsoft.OSTCExtensions",     "type": "CustomScriptForLinux",     "typeHandlerVersion": "1.4",     "settings": {       "fileUris": [ ],       "commandToExecute": "[concat('/bin/bash -c \'echo \"export DOCKER_HOST=:2375\" >> /home/', parameters('adminUsername') ,'/.profile\'')]",       "timestamp": 123456789     }   } }, 
like image 545
Poul K. Sørensen Avatar asked Nov 29 '15 18:11

Poul K. Sørensen


People also ask

How do you escape a single quote?

Single quotes need to be escaped by backslash in single-quoted strings, and double quotes in double-quoted strings.

How do you escape a single quote in terminal?

A single quote is not used where there is already a quoted string. So you can overcome this issue by using a backslash following the single quote. Here the backslash and a quote are used in the “don't” word.


1 Answers

You escape Azure ARM functions in the same way as with VB strings: you simply double the single quote characters.

[concat('This is a ''quoted'' word.')] 

outputs

This is a 'quoted' word. 

Double quotes still needs to be escaped from JSON.

 [concat('''single'' and \"double\" quotes.')] 

outputs

'single' and "double" quotes. 
like image 142
Eric Cote Avatar answered Sep 21 '22 11:09

Eric Cote