How to escape ampersands, semicolons, and curly braces in command-line powershell params?

前端 未结 2 1664
故里飘歌
故里飘歌 2020-12-09 08:42

I\'m using a powershell script to generate a config file with database passwords and the like. The normal use of this script is to generate-and-use a password, but for a fle

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 09:25

    powershell .\makeConfig.ps1 -password "'xxx

    Here

    • outer " double quotes would escape all cmd poisonous characters e.g. <, & etc. excepting " itself and % percentage sign (and ! exclamation mark if delayed expansion is enabled) while
    • inner ' apostrophes (single quotes) would escape all powershell ones (excepting ' apostrophe itself).

    However, exceptions noticed above could be escaped as well… Based on both Escape characters, Delimiters and Quotes articles:

    • in cmd and batch-file
    • in powershell

提交回复
热议问题