Reputation: 39916
I have numerous fields to quote or double quote depending on the cases, so I have made a functions to do that.
Namely
function Add-SingleQuotes
{
param([string] $input)
$str_return = "'" + $input + "'"
return $str_return
}
However the result of this function is ''
, whatever the input I give. Why is it so ?
On the contrary, if I enter manually "'" + "4" + "'"
the result is indeed '4'
.
Upvotes: 2
Views: 56
Reputation: 23713
$Input
is indeed reserved and holds the object(s) in the pipeline.
This is how you might use the $Input variable in your script:
function Add-SingleQuotes {
return "'" + $input + "'"
}
4 | Add-SingleQuotes
Which results into '4'
Upvotes: 1
Reputation: 58471
$input
seems to be a reserved word but I can't find a reference to it that makes sense to me.
Changing it to $inp
works for me.
Upvotes: 3