Home > Software engineering >  How to concatenate two variables from azure variable group and assign them to one with single quotes
How to concatenate two variables from azure variable group and assign them to one with single quotes

Time:10-22

I'm having 2 Variables inside a variable group and their values are as shown below:

cr  2200
tr  cd1200

I would like to assign these two variables to a third variable cd as shown below:

cd  '2200;cd1200;abc.txt'

I'm trying to use below script but it is showing too many arguments. Can someone please help in this.

I'm using below code:

cd = \'"$cr";"$tr";abc.txt\'
echo "$cd"

I need output as:

cd = '2200;cd1200;abc.txt'

CodePudding user response:

Using Azure macro syntax ($(<varName>)):

$cd = '$(cr);$(tr);abc.txt'

Note:

  • PowerShell always needs the $ sigil when accessing a variable - even when assigning to it (unlike in POSIX-compatible shells such as Bash).

  • Azure's macro syntax - which textually expands references to Azure variables up front, before PowerShell sees the code, is not be confused with PowerShell's subexpression operator ($(...))

  • Related