I have the following, perfectly working ps1 script:
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$currentDir = Get-ScriptDirectory
node $currentDir/yarn.js $args
I would like to eliminate the $currentDir variable. I am trying to run:
function Get-ScriptDirectory {
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
node (Get-ScriptDirectory)/yarn.js $args
But this fails - it looks like Get-ScriptDirectory output becomes the first argument. I've tried using quotes, and that doesn't work either - the brackets no longer expand.
How do I run a command using the output of a function?
$()and()anyway? Add it as an answer and I'll mark it correct.