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
aliteralmind
20.2k17 gold badges80 silver badges109 bronze badges
-
1You need to create alias for the above command in bash_aliases file.Avinash Raj– Avinash Raj2015年09月18日 16:28:28 +00:00Commented Sep 18, 2015 at 16:28
-
possible duplicate of how to run python script without typing 'python ...'tripleee– tripleee2015年09月21日 05:03:08 +00:00Commented Sep 21, 2015 at 5:03
2 Answers 2
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.
answered Sep 18, 2015 at 16:32
gen_Eric
228k42 gold badges304 silver badges343 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
- add the following line at the beginning of the script:
#!/usr/bin/env python
rename
hello.pytohellochange the script to be executable:
chmod 755 hello
answered Sep 18, 2015 at 16:34
acw1668
48k5 gold badges30 silver badges39 bronze badges
Comments
default