Reputation: 7019
How to pass the output of a powershell function as an argument to a command?
I was unsuccessful with what I thought was a very straightforward command:
git checkout -b SimplifyName("Test 1")
output is an error:
fatal: 'Test 1' is not a commit and a branch 'SimplifyName' cannot be created from it
where, for the sake of this question,
function SimplifyName ([string] $str = "UNDEFINED") {
$result = $str.Trim().ToLowerInvariant() -replace "[^a-z0-9]+","_"
Write-Output $result
}
From what I understand, anything that follows -b
is taken as space-delimited string arguments for the git checkout -b
command.
I am struggling to find a good help resource for this too since I am possibly using incorrect terminology.
Upvotes: 3
Views: 524
Reputation: 13227
$()
is a subexpression operator, it means 'evaluate this first, and do it separately as an independent statement'.
Here it's used to evaluate the function and then use the output from it for the git
command:
git checkout -b $(SimplifyName "Test 1")
Upvotes: 5