2

I like to make a lot of changes to my $profile file. After saving a change, I would like to source the file using an "sop" alias. Here's how I hope to accomplish that:

set-alias sop Source-Profile
function Source-Profile {
    . $profile
}

This function does not throw any errors, so it appears to work. However, when I do make changes to my $profile file, this function doesn’t appear to to anything. I still have to type . $profile from the PS prompt to re-evaluate that file. And that's ok, but it is a minor pain. I would rather use an alias to source that file.

What am I missing here?

Tom Purl
  • 549
  • 1
  • 3
  • 13

1 Answers1

2

Dot-sourcing a file runs it in the current scope (rather than its own scope). To source a file in a function and get the definitions in the file to be included in the calling scope, you need to dot-source the function. Try this:

. sop
Mike Shepard
  • 748
  • 3
  • 7
  • Awesome, this works! Too bad though that you can't do this without the dot. This sort of thing works in BASH and such. – Tom Purl Mar 05 '13 at 16:33