Mac – The command for alias local=’…’ gets run on terminal open

aliasbashmacmojaveterminal

I have an alias set up in my .bash_profile file: alias local='npm run start-local', and for whatever reason when I open a new terminal session it is trying to run that command npm run start-local immediately. It works fine if I rename it to "local2". What could be causing this?

I got this alias from my coworker who uses it regularly, and the only difference I know of is that he is not on Mojave.

Edit: something interesting I noticed is that if I change it to alias local='echo ' then I see

NVM_AUTO_MODE
NVM_CURRENT
NVM_MODE
VERSION
-bash: fork: Resource temporarily unavailable

Which adds evidence that it is running my local command when something is trying to use the local variable.

Best Answer

I could not recreate what you have said is happening to you.

Saying that I would say that: It is really very dangerous to invoke local as your alias

Because the word local is a shell builtin, a reserved word for the default Bash shell to define a local variable in Bash script inside a Bash function. If you do type local from a new terminal window after removing it from your alias or by unalias local and then you would see it says:

local is a shell builtin

That is why, when you changed your alias to local2 from local it worked fine since local2 is not a shell builtin.

However, if you are using Korn Shell (version 93u+), local is not a shell builtin there. But, in most other shells local is a reserved word or shell builtin. So, in short: local should not be stored as an alias

For more information about shell builtin, look at man page: man builtin

Also, as mentioned by Gordon Davidson, there is definitely something calling the local variable and since you have overridden it as an alias for npm, it is running each time you are opening a new session.