2

I've got an initialisation script that sets a couple of variables for later use. The last line defines a "prompt" function, which I hoped would change my prompt, as an indication that the initialization had been done. The variables get set, so it's not running as a sub-process, but my prompt stays stubbornly at "PS ". What's going wrong?

Here's the script, with two versions of the function I've tried

$II_SYSTEM = "F:\Apps\Ingres92"
$env:PATH = "$II_SYSTEM\ingres\bin;$II_SYSTEM\ingres\utility;$env:PATH"
$env:LIB = "$II_SYSTEM\ingres\lib;$env:LIB"
$INCLUDE = "$II_SYSTEM\ingres\files;$INCLUDE"

function prompt{"PS $PWD IX>"}
function prompt{write-output ("PS $PWD IX>") -nonewline}

Thanks.

1
  • if you want the initialization to always happen, do it in the profile. Changing prompt there definitely works. See Get-Help about_Profiles. Commented May 20, 2013 at 13:59

1 Answer 1

7

You need to call your script file with dot-source:

. .\myscript.ps1

This make available variables and functions created at script level to global scope. Or change the script like this:

function global:prompt{"PS $PWD IX>"}
function global:prompt{write-output ("PS $PWD IX>") -nonewline}

and call it normally.

Sign up to request clarification or add additional context in comments.

2 Comments

So simple when you know how!
So simple when you know how! Thanks.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.