Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Bug in parsing or processing of a function definition?

Reply
 
Old 01-21-2007   #1 (permalink)
Andrew Watt [MVP]


 
 

Bug in parsing or processing of a function definition?

Can others reproduce what seems to be a bug in the parsing or
processing of a function definition?

PS C:\PowerShellScripts> function global:script: {write-host "From a
globally scoped script"}
PS C:\PowerShellScripts> script:
The term 'script:' is not recognized as a cmdlet, function, operable
program, or script file. Verify the term and try a
gain.
At line:1 char:7
+ script: <<<<

Superficially there seems to be no function named "script:" but it
exists as you can demonstrate using the following command (easier to
read on screen in PowerShell):

PS C:\PowerShellScripts> dir function:sc*

CommandType Name Definition
----------- ---- ----------
Function script: write-host "From a globally scoped script"

And it executes if you use the following command:

PS C:\PowerShellScripts> global:script:
From a globally scoped script
PS C:\PowerShellScripts>

But it seems to be specific to the name "script:". See the following:

PS C:\PowerShellScripts> function global:something: {write-host "From
a globally scoped script"}
PS C:\PowerShellScripts> something:
From a globally scoped script
PS C:\PowerShellScripts> global:something:
From a globally scoped script
PS C:\PowerShellScripts>

If the "name" of the function "global:script:" is recognized as
"script:" surely it should be possible to execute the script using its
name.

Looks like a bug to me. Can others reproduce?

Thanks

Andrew Watt MVP

My System SpecsSystem Spec
Old 01-21-2007   #2 (permalink)
RichS


 
 

RE: Bug in parsing or processing of a function definition?

Yes it is reproducible & I think its related to the fact that there is a
script scope takes precedence & that is where PowerShell is looking for the
function
--
Richard Siddaway

Please note that all scripts are supplied "as is" and with no warranty


"Andrew Watt [MVP]" wrote:

> Can others reproduce what seems to be a bug in the parsing or
> processing of a function definition?
>
> PS C:\PowerShellScripts> function global:script: {write-host "From a
> globally scoped script"}
> PS C:\PowerShellScripts> script:
> The term 'script:' is not recognized as a cmdlet, function, operable
> program, or script file. Verify the term and try a
> gain.
> At line:1 char:7
> + script: <<<<
>
> Superficially there seems to be no function named "script:" but it
> exists as you can demonstrate using the following command (easier to
> read on screen in PowerShell):
>
> PS C:\PowerShellScripts> dir function:sc*
>
> CommandType Name Definition
> ----------- ---- ----------
> Function script: write-host "From a globally scoped script"
>
> And it executes if you use the following command:
>
> PS C:\PowerShellScripts> global:script:
> From a globally scoped script
> PS C:\PowerShellScripts>
>
> But it seems to be specific to the name "script:". See the following:
>
> PS C:\PowerShellScripts> function global:something: {write-host "From
> a globally scoped script"}
> PS C:\PowerShellScripts> something:
> From a globally scoped script
> PS C:\PowerShellScripts> global:something:
> From a globally scoped script
> PS C:\PowerShellScripts>
>
> If the "name" of the function "global:script:" is recognized as
> "script:" surely it should be possible to execute the script using its
> name.
>
> Looks like a bug to me. Can others reproduce?
>
> Thanks
>
> Andrew Watt MVP
>

My System SpecsSystem Spec
Old 01-22-2007   #3 (permalink)
Oisin Grehan


 
 

Re: Bug in parsing or processing of a function definition?

The problem stems from using a colon ( : ) in the name of the function.
Powershell uses paths to everything -- functions are referenced by
paths, variables are referenced by paths etc etc. These paths use
colons as delimiters and if you start naming things with embedded
colons, you're asking for trouble. Ideally, powershell should not allow
leaf or container nodes in a path to be named with a colon in them for
any provider, but I guess they never came up with a satisfying solution
for that one. They cannot be escaped even with the backtick... the best
you can do is to remove ambuigity in the path by fully qualifying it:

PS > function global:script: { write-host "hello, world." }

PS > gc Function::global:script:
write-host "hello, world."

While I can retrieve the body, I haven't been able to execute it
either... :-|

- Oisin

Andrew Watt [MVP] wrote:
> Can others reproduce what seems to be a bug in the parsing or
> processing of a function definition?
>
> PS C:\PowerShellScripts> function global:script: {write-host "From a
> globally scoped script"}
> PS C:\PowerShellScripts> script:
> The term 'script:' is not recognized as a cmdlet, function, operable
> program, or script file. Verify the term and try a
> gain.
> At line:1 char:7
> + script: <<<<
>
> Superficially there seems to be no function named "script:" but it
> exists as you can demonstrate using the following command (easier to
> read on screen in PowerShell):
>
> PS C:\PowerShellScripts> dir function:sc*
>
> CommandType Name Definition
> ----------- ---- ----------
> Function script: write-host "From a globally scoped script"
>
> And it executes if you use the following command:
>
> PS C:\PowerShellScripts> global:script:
> From a globally scoped script
> PS C:\PowerShellScripts>
>
> But it seems to be specific to the name "script:". See the following:
>
> PS C:\PowerShellScripts> function global:something: {write-host "From
> a globally scoped script"}
> PS C:\PowerShellScripts> something:
> From a globally scoped script
> PS C:\PowerShellScripts> global:something:
> From a globally scoped script
> PS C:\PowerShellScripts>
>
> If the "name" of the function "global:script:" is recognized as
> "script:" surely it should be possible to execute the script using its
> name.
>
> Looks like a bug to me. Can others reproduce?
>
> Thanks
>
> Andrew Watt MVP


My System SpecsSystem Spec
Old 01-22-2007   #4 (permalink)
Oisin Grehan


 
 

Re: Bug in parsing or processing of a function definition?

belay the previous gibber!

I can execute it; simply:

PS >global:script:
hello, world.

And just to add, yes, RichS is right -- powershell will parse "script:"
as a namespace qualifier before a function name. There is a precedence
to this - it's listed online somewhere.

- Oisin

Oisin Grehan wrote:
> The problem stems from using a colon ( : ) in the name of the function.
> Powershell uses paths to everything -- functions are referenced by
> paths, variables are referenced by paths etc etc. These paths use
> colons as delimiters and if you start naming things with embedded
> colons, you're asking for trouble. Ideally, powershell should not allow
> leaf or container nodes in a path to be named with a colon in them for
> any provider, but I guess they never came up with a satisfying solution
> for that one. They cannot be escaped even with the backtick... the best
> you can do is to remove ambuigity in the path by fully qualifying it:
>
> PS > function global:script: { write-host "hello, world." }
>
> PS > gc Function::global:script:
> write-host "hello, world."
>
> While I can retrieve the body, I haven't been able to execute it
> either... :-|
>
> - Oisin
>
> Andrew Watt [MVP] wrote:
> > Can others reproduce what seems to be a bug in the parsing or
> > processing of a function definition?
> >
> > PS C:\PowerShellScripts> function global:script: {write-host "From a
> > globally scoped script"}
> > PS C:\PowerShellScripts> script:
> > The term 'script:' is not recognized as a cmdlet, function, operable
> > program, or script file. Verify the term and try a
> > gain.
> > At line:1 char:7
> > + script: <<<<
> >
> > Superficially there seems to be no function named "script:" but it
> > exists as you can demonstrate using the following command (easier to
> > read on screen in PowerShell):
> >
> > PS C:\PowerShellScripts> dir function:sc*
> >
> > CommandType Name Definition
> > ----------- ---- ----------
> > Function script: write-host "From a globally scoped script"
> >
> > And it executes if you use the following command:
> >
> > PS C:\PowerShellScripts> global:script:
> > From a globally scoped script
> > PS C:\PowerShellScripts>
> >
> > But it seems to be specific to the name "script:". See the following:
> >
> > PS C:\PowerShellScripts> function global:something: {write-host "From
> > a globally scoped script"}
> > PS C:\PowerShellScripts> something:
> > From a globally scoped script
> > PS C:\PowerShellScripts> global:something:
> > From a globally scoped script
> > PS C:\PowerShellScripts>
> >
> > If the "name" of the function "global:script:" is recognized as
> > "script:" surely it should be possible to execute the script using its
> > name.
> >
> > Looks like a bug to me. Can others reproduce?
> >
> > Thanks
> >
> > Andrew Watt MVP


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Data Parsing?????? PowerShell
Data parsing - .NET PowerShell
parsing xml VB Script
BUG - backtick-parsing at end of line makes linefeed part of function name PowerShell
BUG: Redirecting function contents to a file truncates function lines at the width of the console PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46