Author Posts

September 7, 2014 at 3:01 pm

We all know that many unix shells have it and the format for powershell is $ (command ). But I can't find it documented anywhere. In the first edition of the book powershell TFM, it is mentioned, but the later edition lacks it. is it still around? I tried mkdir $ (1+3) and received error

mkdir : A positional parameter cannot be found that accepts argument '4'.
At line:1 char:1
+ mkdir $ (1+3)
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [mkdir], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,mkdir

what gives?

September 7, 2014 at 3:06 pm


Is called a subexpression, and it's valid inside double quotes. Notice there is no space between the dollar sign and the parentheses. You used a space; that passed $ as the first argument, and 4 (the result of the expression 1+3) as a second parameter. The command didn't know what to do with the second parameter.

If your goal was to create a directory named 4, you don't need to use a subexpression.

mkdir (1+3)

Would have worked. Parenthetical expressions are always evaluated first, and the result passed to whatever parameter.

September 7, 2014 at 4:51 pm

thanks a lot. BTW. what happened to the PowerShell TFM book, the publisher announced new editions, but there are nowhere to be found. what gives?

September 7, 2014 at 5:08 pm

You'd have to ask them. I'm not involved with the book any longer.