Null coalescing in powershell

后端 未结 10 1145
遇见更好的自我
遇见更好的自我 2020-11-29 21:57

Is there a null coalescing operator in powershell?

I\'d like to be able to do these c# commands in powershell:

var s = myval ?? \"new value\";
var x         


        
10条回答
  •  星月不相逢
    2020-11-29 22:19

    Finally, PowerShell 7 got Null Coalescing assignment operators!

    PS > $null ?? "a"
    a
    PS > "x" ?? "y"
    x
    PS > $x = $null
    PS > $x ??= "abc"
    PS > $x
    abc
    PS > $x ??= "xyz"
    PS > $x
    abc
    

提交回复
热议问题