$installLocation = "C:\hello\world"
$packageName = "hello"
Write-Host "if ("$installLocation" -match '${packageName}|bla') {"
if ("$installLocation" -match '${packageName}|bla') {
Write-Host "hello";
}
if ("$installLocation" -match 'hello|bla') {
Write-Host "world";
}
当前结果
if ( C:\hello\world -match 'hello|bla') {
world
预期结果
if ( C:\hello\world -match 'hello|bla') {
hello
world
答案 0 :(得分:1)
您需要在变量周围使用双引号。
试试这个:
$packageName = "hello"
echo '${packageName}|bla'
echo "${packageName}|bla"
结果是:
${packageName}|bla
hello|bla
因此,要修复脚本,请使用:
if ("$installLocation" -match "${packageName}|bla") {
Write-Host "hello";
}
给出了结果:
hello
world