简体   繁体   中英

Porting bat code to powershell

Porting my bat scripts to PowerShell. Two problems: $info expands in strings like "$info" ; when running commands from a file somewhere spoil the arguments (in interactive mode appears only the first problem. the console output "hg tip: invalid arguments").

Command:

hg tip --template "<?php\r\n// ќв®  ўв®¬ вЁзҐбЄЁ бЈҐ­ҐаЁа®ў ­­л© д ©« б Ё­д®а¬ жЁҐ© ® ⥪г饬 ЎЁ«¤Ґ ¬®¤г«п\r\n$info = array(\r\n'rev' => '{rev}',\r\n'date' => '{date|isodate}',\r\n'changeset' => '{node}',\r\n);" > modules/video/version.php

Also, another way is to use single-quotes instead of double quotes you are using now.

update:

Ok, so basically you have 3 approaches.

  • Single-quotes - Expressions are not evaluated. But you need to escape the single-quote sign.
  • Double-quotes - Expressions are evaluated. So, if you want to use $ sign you need to escape it.
  • Here-strings - Either single, or double-quotes (evaluated/not evaluated). Strings can span multiple lines. You don't need to escape anything if you use single quote approach

Example for third approach:

[12:06:58 PM] ~> $str = @'
'$'`#'"<>\/@
'@ 


_______________________________________________________________________________________________________________________________________________________________________________________________
[12:07:15 PM] ~> $str
'$'`#'"<>\/@

to not evaluate $info as variable you must write it as `$info . Like:

 hg tip --template "<?php\r\n// ќв®  ўв®¬ вЁзҐбЄЁ бЈҐ®ў © д ©« б Ё®а¬ жЁҐ© ® ⥪г饬 ЎЁ«¤Ґ ¬®¤г«п\r\n`$info = array(\r\n'rev' => '{rev}',\r\n'date' => '{date|isodate}',\r\n'changeset' => '{node}',\r\n);" > modules/video/version.php

$ is powershell keyword therefore `$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM