Why isn’t my PowerShell alias for reloading the profile working?

0
4
Asked By CuriousCoder99 On

I'm trying to create an alias in PowerShell to reload my profile quickly using `. $PROFILE`. I set up a function called `so`, but when I tried to use it after modifying my profile, it didn't work. However, executing `. $PROFILE` directly works fine. Is there something about scoping or the way I set this up that I'm missing? Here's what I did:

```powershell
# alias in my profile
function so {
. $PROFILE
}
```

Then in my session, I modified my profile with:`vim $PROFILE` and tried `so`, but it didn't reload. The command `. $PROFILE` works as expected.

2 Answers

Answered By TechieTinker On

It sounds like you might be running into a scoping issue. When you define a function like `so` to dot-source your profile, it might not be executing in the global scope. A tip is to try adding an extra dot when calling it to run in the correct scope. It should look like this: `. so`. This should help you reload your profile as expected!

CodeCrafter42 -

Yeah, definitely give that a shot! Scoping can be tricky in PowerShell.

Answered By DevDynamo On

I've had a similar issue before. Instead of `so`, I created a function called `reload-profile` that uses `& $PROFILE` to run the profile. It seems to work better for me in terms of reloading.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.