Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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
share|improve this answer
    
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 5 '13 at 16:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.