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 - function to delete a function

Reply
 
Old 06-16-2009   #1 (permalink)
Larry__Weiss


 
 

function to delete a function

How would a function be written that given a name of a function, would
delete that function?

I tried with no success

function rif { ri function:$Args[0] }

- Larry

My System SpecsSystem Spec
Old 06-16-2009   #2 (permalink)
Chad


 
 

RE: function to delete a function

This seems to work:

function rif { param($f) ri function:$f }

"Larry__Weiss" wrote:
Quote:

> How would a function be written that given a name of a function, would
> delete that function?
>
> I tried with no success
>
> function rif { ri function:$Args[0] }
>
> - Larry
>
My System SpecsSystem Spec
Old 06-19-2009   #3 (permalink)
Larry__Weiss


 
 

args[0] within a doublequoted string

Consider these two versions of function testArgs0_1

function testArgs0_1 { '$Args[0]' + ' ' + $Args[0] + ' ' + '$Args[1]' +
' ' +
$Args[1]}
testArgs0_1 xxx yyy
produces
$Args[0] xxx $Args[1] yyy

function testArgs0_1 { '$Args[0]' + ' ' + "$Args[0]" + ' ' + '$Args[1]'
+ ' '
+ "$Args[1]"}
testArgs0_1 xxx yyy
produces
$Args[0] xxx yyy[0] $Args[1] xxx yyy[1]

Why does putting double quotes around $Args[0] and $Args[1] make that
difference?

- Larry

My System SpecsSystem Spec
Old 06-19-2009   #4 (permalink)
Larry__Weiss


 
 

Re: args[0] within a doublequoted string

function testArgs0_1 { $Args0 = $Args[0]; $Args1 = $Args[1]; '$Args[0]'
+ ' ' + "$Args0" + ' ' + '$Args[1]' + ' ' + "$Args1"}
testArgs0_1 xxx yyy
produces
$Args[0] xxx $Args[1] yyy

and works as I expected it to as it avoids a dynamic string expansion
involving $Args[0]

The dynamic string expander seems to stop at the [ character instead of
parsing
the entire $Args[0] token for replacement.

- Larry



Larry__Weiss wrote:
Quote:

> Consider these two versions of function testArgs0_1
>
> function testArgs0_1 { '$Args[0]' + ' ' + $Args[0] + ' ' + '$Args[1]'
+ ' ' + $Args[1]}
Quote:

> testArgs0_1 xxx yyy
> produces
> $Args[0] xxx $Args[1] yyy
>
> function testArgs0_1 { '$Args[0]' + ' ' + "$Args[0]" + ' ' +
'$Args[1]' + ' ' + "$Args[1]"}
Quote:

> testArgs0_1 xxx yyy
> produces
> $Args[0] xxx yyy[0] $Args[1] xxx yyy[1]
>
> Why does putting double quotes around $Args[0] and $Args[1] make that
difference?
Quote:

>
My System SpecsSystem Spec
Old 06-19-2009   #5 (permalink)
Larry__Weiss


 
 

Re: args[0] within a doublequoted string

(I'm so sorry about the HTML versions of my postings...here is a version
of my last post now in plaintext)


function testArgs0_1 { $Args0 = $Args[0]; $Args1 = $Args[1]; '$Args[0]'
+ ' ' + "$Args0" + ' ' + '$Args[1]' + ' ' + "$Args1"}
testArgs0_1 xxx yyy
produces
$Args[0] xxx $Args[1] yyy

and works as I expected it to as it avoids a dynamic string expansion
involving $Args[0]

The dynamic string expander seems to stop at the [ character instead of
parsing the entire $Args[0] token for replacement.

Consider these two versions of function testArgs0_1

function testArgs0_1 { '$Args[0]' + ' ' + $Args[0] + ' ' + '$Args[1]'
+ ' ' + $Args[1]}
testArgs0_1 xxx yyy
produces
$Args[0] xxx $Args[1] yyy

function testArgs0_1 { '$Args[0]' + ' ' + "$Args[0]" + ' ' + '$Args[1]'
+ ' ' + "$Args[1]"}
testArgs0_1 xxx yyy
produces
$Args[0] xxx yyy[0] $Args[1] xxx yyy[1]

Why does putting double quotes around $Args[0] and $Args[1] make that
difference?

- Larry
My System SpecsSystem Spec
Old 06-20-2009   #6 (permalink)
Larry__Weiss


 
 

Re: args[0] within a doublequoted string

I figured it out. You have to wrap it with a $() block as in

function testArgs0_1 { '$Args[0]' + ' ' + "$($Args[0])" + ' ' +
'$Args[1]' + ' ' + "$($Args[1])"}
testArgs0_1 xxx yyy
produces
$Args[0] xxx $Args[1] yyy

- Larry



Larry__Weiss wrote:
Quote:

> function testArgs0_1 { $Args0 = $Args[0]; $Args1 = $Args[1]; '$Args[0]'
> + ' ' + "$Args0" + ' ' + '$Args[1]' + ' ' + "$Args1"}
> testArgs0_1 xxx yyy
> produces
> $Args[0] xxx $Args[1] yyy
>
> and works as I expected it to as it avoids a dynamic string expansion
> involving $Args[0]
>
> The dynamic string expander seems to stop at the [ character instead of
> parsing
> the entire $Args[0] token for replacement.
>
> - Larry
>
>
>
> Larry__Weiss wrote:
Quote:

> > Consider these two versions of function testArgs0_1
> >
> > function testArgs0_1 { '$Args[0]' + ' ' + $Args[0] + ' ' + '$Args[1]'
> + ' ' + $Args[1]}
Quote:

> > testArgs0_1 xxx yyy
> > produces
> > $Args[0] xxx $Args[1] yyy
> >
> > function testArgs0_1 { '$Args[0]' + ' ' + "$Args[0]" + ' ' +
> '$Args[1]' + ' ' + "$Args[1]"}
Quote:

> > testArgs0_1 xxx yyy
> > produces
> > $Args[0] xxx yyy[0] $Args[1] xxx yyy[1]
> >
> > Why does putting double quotes around $Args[0] and $Args[1] make that
> difference?
Quote:

> >
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
About the function. PowerShell
function not working dispite working outside the function block PowerShell
Every left click or highlight prompts delete function in Vista Vista General
Windows Vista Email IMAP Message Delete Function Vista mail
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