Powershell pitfalls

后端 未结 21 1352
梦谈多话
梦谈多话 2020-12-23 01:44

What Powershell pitfalls you have fall into? :-)

Mine are:

# -----------------------------------
function foo()
{
    @(\"text\")
}

# Expected 1, a         


        
21条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 02:36

    My personal favorite is

    function foo() {
      param ( $param1, $param2 = $(throw "Need a second parameter"))
      ...
    }
    
    foo (1,2)
    

    For those unfamiliar with powershell that line throws because instead of passing 2 parameters it actually creates an array and passes one parameter. You have to call it as follows

    foo 1 2
    

提交回复
热议问题