Escaping quotes and double quotes

后端 未结 3 1471
说谎
说谎 2020-11-29 04:11

How do I properly escape the quotes in the -param value in the following command line?

$cmd=\"\\\\server\\toto.exe -batch=B -param=\"sort1;parmt         


        
3条回答
  •  情话喂你
    2020-11-29 04:39

    Using the backtick (`) works fine for me if I put them in the following places:

    $cmd="\\server\toto.exe -batch=B -param=`"sort1;parmtxt='Security ID=1234'`""
    

    $cmd returns as:

    \\server\toto.exe -batch=B -param="sort1;parmtxt='Security ID=1234'"
    

    Is that what you were looking for?

    The error PowerShell gave me referred to an unexpected token 'sort1', and that's how I determined where to put the backticks.

    The @' ... '@ syntax is called a "here string" and will return exactly what is entered. You can also use them to populate variables in the following fashion:

    $cmd=@'
    "\\server\toto.exe -batch=B -param="sort1;parmtxt='Security ID=1234'""
    '@
    

    The opening and closing symbols must be on their own line as shown above.

提交回复
热议问题