In PowerShell I can do this:
function Get-Foo()
{
Write-Host "Calculating result..."
return 42
}
$x = Get-Foo
Write-Host "The answer is $x" # output: The answer is 42
So Calculating result..
is output to the console, but it's not present in the pipeline so I can just take the method's "return value" and it works
However in bash I don't have Write-Host
and something like this won't work:
function getfoo {
echo "Calculating result..."
echo "42"
}
x=$(getfoo)
echo $x # output will include "Calculating result..."
I realize I can save to a file and print after, just wondering if there's a more elegant alternative