The following is a powershell script article:
function PickANumber() { 12 } function GetTheAnswer() { PickANumber + 30 } $answer = GetTheAnswer write-output "The answer is $answer"
The output of this script:
The answer is 12
As far as I suppose, this is due to the fact that calls to powershell functions do not have brackets around the arguments or commas between them, so PickANumber + 30 parsed as PickANumber('+', 1) instead of PickANumber() + 1 . And this is not a mistake, unused arguments are simply ignored (for example, using JavaScript).
If you change it a little, then the answer will be 42:
function GetTheAnswer() { $a = PickANumber $a + 30 }
But of course, is there a way to do this on one line?
I am posting here because it will also bite someone else.
source share