0

I have a test branch, I want to test its existence with -contains, but it doesn't seem to work ?

$test = git branch
if ($test -contains "test") {
    Write-Host "success"
}
mklement0
  • 382,024
  • 64
  • 607
  • 775
user310291
  • 36,946
  • 82
  • 271
  • 487
  • what's the output of `git branch`? the `-contains` operator is quite literal when it comes to its name, just means"*test*" is being searched in an array. – Abraham Zinala Mar 11 '22 at 23:12
  • 2
    [`-contains` / `-notcontains`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Comparison_Operators#-contains-and--notcontains) are _collection_ operators: they test if the LHS object is _equal in full_ to at least one element of the RHS collection. They are not to be confused with the `.Contains()` .NET method for _substring matching_. While PowerShell has no equivalent operator for _literal_ substring matching, you can use `-like` with _wildcard expressions_ or `-match` with _regular expressions_, both of which are case-_insensitive_ by default. – mklement0 Mar 11 '22 at 23:13