2

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'.

2 Answers 2

3

$input seems to be a reserved word but I can't find a reference to it that makes sense to me.

  1. $input gotchas perhaps

Changing it to $inp works for me.

1

$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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.