0

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.

  • Is your coworker using as bash shell? – David Anderson May 14 at 18:55
3

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. 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.

  • 2
    I'll bet there's something in one of the shell startup scripts that tries to use local for its normal function (declaring a local shell variable), and because of the alias it's running npm instead. Not having the variable declared properly may prevent the script from working properly. This is why it's really dangerous to override standard commands unless you know exactly what you're doing. – Gordon Davisson May 14 at 19:41
  • I was also wondering, what would happen if a script is using local before the variable declaration! Each time the script might just run npm instead of defining the variable. – Rakib Fiha May 15 at 1:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .