Shell Script: Execute a python program from within a shell script - Stack Overflow
Learning python
To all experts: Shell as a scripting language vs Python as a scripting language
Can Python (efficiently) replace all bash scripting, or is bash still worth learning/using at times?
In terms of ability, python can do anything bash can do and more.
Some things are quicker to hack up using bash due to existing integrations within the linux ecosystem.
Basic bash scripting is good to know, in case you need to make a bash script that installs a specific python version :)
More on reddit.comCan I execute shell commands directly from Python scripts?
How does Python compare to traditional shell scripting languages like Bash?
How can I optimize Python shell scripts for performance?
Videos
Just make sure the python executable is in your PATH environment variable then add in your script
python path/to/the/python_script.py
Details:
- In the file job.sh, put this
#!/bin/sh python python_script.py
- Execute this command to make the script runnable for you :
chmod u+x job.sh - Run it :
./job.sh
Method 1 - Create a shell script:
Suppose you have a python file hello.py
Create a file called job.sh that contains
#!/bin/bash
python hello.py
mark it executable using
$ chmod +x job.sh
then run it
$ ./job.sh
Method 2 (BETTER) - Make the python itself run from shell:
Modify your script hello.py and add this as the first line
#!/usr/bin/env python
mark it executable using
$ chmod +x hello.py
then run it
$ ./hello.py
My take:
Python is probably a great language(what I saw and importantly, used for very little time), but that never enticed me to stick with it on a long-term basis.
See! The shortcoming and understanding. Some conventions in that language look and importantly, feel ridiculous.
My lacuna ...so I refrained from it as much as possible. That certainly does NOT demean Python's ability.
Shell is comparatively easy (take it with a pinch of salt :) ) to learn and use. And it certainly has some eye-popping drawbacks. But the world used to run on it and still some do.
What do you use more frequently?
PS: There is a catch, for the month-end paycheck you are force to use something, that you might not like. I am ignoring that "important fact" in this argument. Looking for pure technical merits.