How to return one and only one value from a PowerShell function?

前端 未结 10 911
暖寄归人
暖寄归人 2020-12-24 01:17

I\'ve learned from this Stack Overflow question, that PowerShell return semantics are different, let\'s say, from C#\'s return semantics. Quote from the aforementioned quest

10条回答
  •  一个人的身影
    2020-12-24 02:06

    echo is an alias for Write-Output which sends the object to the next command.

    Using Write-Host should help:

    PS:> function Calculate
    >> {
    >>    # Every function that returns has to echo something
    >>    Write-Host "test"
    >>    return 11
    >> }
    >>
    PS:> $A = Calculate
    test
    PS:> $A
    11
    

提交回复
热议问题