2

I have a file named run. These are the contents:

#!/bin/zsh

python

To make the file executable, I ran chmod a+x run. I typed in ./run into the terminal. It activates the Python 2.7 shell. The reason this is unexpected is because in my .zshrc file I have an alias: alias python="python3". Why does zsh not recognize my alias?

shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34

1 Answers1

4

You need to enable alias processing. Do in your script a

setopt aliases

before defining your alias.

user1934428
  • 19,864
  • 7
  • 42
  • 87
  • It doesn't work? I tried putting it in both `run` **and** `~/.zshrc` and even restarted the shell, but it still doesn't work. The only thing that has worked so far is putting the alias in `run` as @Hedy suggested. – shreyasm-dev Aug 17 '20 at 11:52
  • @GalaxyCat105 : `.zshrc` doesn't matter in this context. It is not processed by your script anyway. **Inside** `run`, you have to do `setopt aliases; alias python="python3"`, as I explained in my answer (_do it **in** your script, **before** defining your alias_) – user1934428 Aug 17 '20 at 12:55