I am a novice with PowerShell.
In Msys2 (or Lnux), I have defined a function npp
npp ()
{
${NPP_PATH} "$@"
}
such that if I call from the command prompt npp
it launches Notepad++ (as defined in ${NPP_PATH}
).
If I call npp "mydir/stage 1/a.txt"
it opens that file for editing.
Generally speaking, it allows:
- Any number of parameters.
- Parameters containing spaces, if suitably escaped.
What would be the equivalent in PowerShell?
I guess in PS I should also go for a function to obtain a similar behavior.
So far, I could receive an undefined number of parameters, and use them in a foreach
loop, see code below.
But I could not find the equivalent of the simple "$@"
to pass all parameters as they are received.
Moreover, if I use quotes in one of the arguments, they are removed, so it will probably have problems with file paths including blanks.
function multi_params {
param(
[Parameter(
ValueFromRemainingArguments=$true
)][string[]]
$listArgs
)
$count = 0
foreach($listArg in $listArgs) {
'$listArgs[{0}]: {1}' -f $count, $listArg
$count++
}
}