Say, I have a python script named hello.py
, which I run on mac as:
$ python hello.py
What do I need to do to run it as:
$ hello
Say, I have a python script named hello.py
, which I run on mac as:
$ python hello.py
What do I need to do to run it as:
$ hello
Add a "shebang" to the top of the file to tell it how to run your script.
#!/usr/bin/env python
Then you need to mark the script as "executable":
chmod +x hello.py
Then you can just run it as ./hello.py
instead of python hello.py
.
To run it as just hello
, you can rename the file from hello.py
to hello
and then copy it into a folder in your $PATH
.
#!/usr/bin/env python
rename hello.py
to hello
change the script to be executable: chmod 755 hello