简体   繁体   中英

How to copy the source of function to another one in Powershell?

Let a function test

function test { }

I want to have function test2 = function test and be able to modify function test without impacting the copy test2: don't know if it is even possible :)

Update: I want to override the original function but kept it under another name so as to be able to call it from the second one.

I know about $function:test but I can't see afterwards how to use it for that purpose.

If you are asking how to copy the content of one function into another:

function function1 {
  "function output"
}

$Function:function2 = $Function:function1

Get-Content Function:function2
# output: "function output"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM