I have python installed on my system as python3
. In my .zshrc
file I defined following alias:
alias python=python3
With this, I am able to run python3
using python
on the command-line:
$ python
Python 3.11.6 (main, Nov 2 2023, 04:39:43) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
But if I write a shell script test.sh
like so:
#!/bin/bash
python
and then try to run this script as follows:
$ ./test.sh
I get:
./test.sh: line 2: python: command not found
What is going on here and how can I fix it? To be clear, this is on Mac but I think the result should be same on Linux. Thanks.
bash
in your script and have it use that alias then put the alias in your.bashrc
, not your.zshrc
, asbash
andzsh
are 2 completely different shells.