Last active
February 2, 2024 06:39
-
-
Save johlju/71d19e8516b8b759e0820491df8c5cbd to your computer and use it in GitHub Desktop.
Konstigt proplem med `-replace`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Innehållet i $b ska ersätta raden "#placeholder parameters" i innehållet av $a. | |
# Men saker får fnatt som man kan se i result.txt och den verkar "loopa" och göra help knasiga saker. | |
# Testat i PS7.4.1 enbart. | |
# Löste det genom att istället använda [RegEx]::Replace(), men vore roligt att veta varför. | |
$a = @' | |
# Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters | |
'@ | |
$b = @' | |
param | |
( | |
[Parameter(Mandatory = $true, ParameterSetName = 'Destination')] | |
[ValidateScript({ | |
Test-Path -Path $_ -PathType 'Container' | |
})] | |
[System.String] | |
$Destination, | |
[Parameter(ParameterSetName = 'Scope')] | |
[ValidateSet('CurrentUser', 'AllUsers')] | |
[System.String] | |
$Scope = 'CurrentUser', | |
[Parameter()] | |
[ValidateScript({ | |
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | |
$_ -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' -or | |
# Need to support the Nuget range syntax as well. | |
$_ -match '^[\[(][0-9\.\,]*[\])]$' | |
})] | |
[System.String] | |
$Version, | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$UseCompatibilityModule, | |
[Parameter()] | |
[ValidateScript({ | |
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | |
$_ -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' -or | |
# Need to support the Nuget range syntax as well. | |
$_ -match '^[\[(][0-9\.\,]*[\])]$' | |
})] | |
[System.String] | |
$CompatibilityModuleVersion = '[3.0.22,]', | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$ImportModule, | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$Force | |
) | |
'@ | |
$a = $a -replace '#placeholder parameters', $b | |
$a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version v#.#.# (yyyy-MM-dd) | |
param | |
( | |
[Parameter(Mandatory = $true, ParameterSetName = 'Destination')] | |
[ValidateScript({ | |
Test-Path -Path # Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -PathType 'Container' | |
})] | |
[System.String] | |
$Destination, | |
[Parameter(ParameterSetName = 'Scope')] | |
[ValidateSet('CurrentUser', 'AllUsers')] | |
[System.String] | |
$Scope = 'CurrentUser', | |
[Parameter()] | |
[ValidateScript({ | |
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | |
# Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))? | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -or | |
# Need to support the Nuget range syntax as well. | |
# Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -match '^[\[(][0-9\.\,]*[\])] | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters | |
})] | |
[System.String] | |
$Version, | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$UseCompatibilityModule, | |
[Parameter()] | |
[ValidateScript({ | |
# From https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | |
# Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -match '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))? | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -or | |
# Need to support the Nuget range syntax as well. | |
# Version v#.#.# (yyyy-MM-dd) | |
#placeholder parameters | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters -match '^[\[(][0-9\.\,]*[\])] | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters | |
})] | |
[System.String] | |
$CompatibilityModuleVersion = '[3.0.22,]', | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$ImportModule, | |
[Parameter()] | |
[System.Management.Automation.SwitchParameter] | |
$Force | |
) | |
$script:moduleName = 'PSResourceGet.Bootstrap' | |
Remove-Module -Name $script:moduleName -Force -ErrorAction 'SilentlyContinue' | |
New-Module -Name $script:moduleName -ScriptBlock { | |
#placeholder localization | |
#placeholder helpers | |
#placeholder Start-PSResourceGetBootstrap | |
#placeholder export | |
} | Import-Module | |
Start-PSResourceGetBootstrap @PSBoundParameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment