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.
$() 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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With