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
Answer from Jean-Bernard Jansen on Stack Overflow
🌐
Medium
medium.com › capital-one-tech › bashing-the-bash-replacing-shell-scripts-with-python-d8d201bc0989
Bashing the Bash — Replacing Shell Scripts with Python | by Steven F. Lott | Capital One Tech | Medium
February 21, 2020 - I’ll assume a little familiarity with Python. The examples will be in Python 3.6 and include features like pathlib and f-strings. If you want to follow along, consider creating a virtual environment or using conda. The shell script examples are pure bash, and will run anywhere that bash runs.
Discussions

To all experts: Shell as a scripting language vs Python as a scripting language
Shell is fine for small glue scripts. Anything larger I use a "real" language. More on reddit.com
🌐 r/linux
90
0
March 25, 2024
How to include python script inside a bash script - Unix & Linux Stack Exchange
For newer releases after 5.1 ... of the shell is 50 or lower, or if the size of the here-document is larger than the pipe buffer size of the system, the here-document is saved to a temporary file. ... You can use heredoc if you want to keep the source of both bash and python scripts together. For example, say the following ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
February 13, 2015
How can I call a shell script from Python code? - Stack Overflow
How can call/run such example.sh file in python? I need to connect to the oracle cloud then, I should use the script you written here. Could you please write the additional code (how to connect an example.sh file which in in OCI)? Thank you. 2021-03-16T12:56:06.183Z+00:00 ... If your shell script ... More on stackoverflow.com
🌐 stackoverflow.com
Shell scripting in Python
plumbum remains my favorite tool for many jobs, getting so much so right so long ago. Here's how it might be used for the tasks in your examples table : initialization (minimal): from plumbum import local # minimal from plumbum.cmd import echo, cat # specify commands as functions from plumbum import FG, BG # shortcuts for foreground/background runs run command: echo["this"] & FG # or: echo["this"].run_fg() read stream: a = echo("this") # or: a = local["echo"]("this") write stream: (cat << "this") & FG # or: (cat << "this").run_fg() # capturing output: (cat << "this")() # or: (local["cat"] << "this")() chain commands: (echo["this"] | cat) & FG # or: (echo["this"] | cat).run_fg() # capturing output: (echo["this"] | cat)() branch out: ret, out, err = cmd.run() (cat << out) & FG (cat << err) & FG # capturing output: (cat << out)() (cat << err)() errors in chains: ret, out, err = echo["this"].run(retcode=(0, 1)) (cat << err) & FG((0, 2)) More on reddit.com
🌐 r/Python
7
0
September 6, 2023
🌐
pytz
pythonhosted.org › scriptine › intro.html
Python shell scripting made easy — scriptine 0.2.0 documentation
#! /usr/bin/env python def hello_command(name, print_counter=False, repeat=10): """Print nice greetings.""" for i in range(repeat): if print_counter: print i+1, print 'Hello, %s!' % name if __name__ == '__main__': import scriptine scriptine.run() This is all you need for a simple script with a hello command. Scriptine brings all the rest you expect from a good shell script: % ./example_hello.py hello --help Usage: example_hello.py hello [options] name Print nice greetings.
🌐
Medium
medium.com › @charlesmwaniki › python-linux-shell-scripting-best-practices-92cb04856aa7
Python-Linux Shell Scripting: Best Practices | by Charles Mwaniki | Medium
February 29, 2024 - Here are some tips for using ... in your Python-Linux shell scripts: Use meaningful names: Choose variable names that accurately describe the value they hold. Avoid using generic or abbreviated names, as they may not provide enough context for other developers to understand what the variable represents. Use underscores: Use underscores to separate words in variable names, as this makes them more readable. For example, use file_path ...
🌐
Python Course
python-course.eu › applications-python › python-and-the-shell.php
2. Python and the Shell | Applications | python-course.eu
It's not possible in Python to read a character without having to type the return key as well. On the other hand this is very easy on the Bash shell. The Bash command read -n 1 waits for a key (any key) to be typed. If you import os, it's easy to write a script providing getch() by using os.system() and the Bash shell.
🌐
GeeksforGeeks
geeksforgeeks.org › python › executing-shell-commands-with-python
Executing Shell Commands with Python - GeeksforGeeks
February 14, 2026 - Example: Here the system() method is used to execute the pwd shell script using Python.
🌐
Codementor
codementor.io › community › using bash and python together (with samples)
Using Bash and Python Together (With Samples) | Codementor
September 11, 2023 - Create Python scripts to perform specific tasks or automation. Python is a versatile language for various automation needs, from file manipulation to web scraping. You can use Python's built-in libraries or install additional packages as needed. Here's a simple example of a Python script that prints "Hello, World!" to the terminal:
Find elsewhere
🌐
Python Land
python.land › home › using the unix shell › how to create a bash script, with example code
How To Create A Bash Script, With Example Code • Python Land Tutorial
February 6, 2022 - We can use conditional programming to improve our previous example, arguments.sh, since it contained a little problem. It expects a name in $1 without checking if it actually gets one. Let’s fix this: ... #!/bin/bash if test -z "$1" then echo "Usage: $0 <Your name>" else echo "Hello $1, from $0" fiCode language: Shell Session (shell)
🌐
GitHub
github.com › lamerman › shellpy
GitHub - lamerman/shellpy: A tool for convenient shell scripting in python · GitHub
run your python scripts as usual with python but initialize shellpython before importing any module with shellpython.init() as in the Example
Starred by 639 users
Forked by 61 users
Languages   Python 98.7% | Smarty 1.3%
🌐
Linux Journal
linuxjournal.com › content › python-scripts-replacement-bash-utility-scripts
Python Scripts as a Replacement for Bash Utility Scripts | Linux Journal
January 16, 2013 - It is as powerful to write Python programs that behave in a UNIX fashion (that is, read in standard input and write to standard output) as it is to write Python replacements for existing shell commands, such as cat and sort. Let's build on the problem that was solved earlier in this article. Besides the work already done, let's find out know how many times a certain user has logged in to the system. The uniq command simply removes duplicates but gives no information on how many duplicates there are. Instead of uniq, a Python script can be used as another command in the chain. Here's a Python program to do this (in my examples, I refer to this file as namescount.py):
🌐
Jon Sprig
jon.sprig.gs › blog › post › 8025
Why (and how) I’ve started writing my Shell Scripts in Python
September 15, 2024 - Here’s a great example · #!/bin/bash i = 0 until [ $i -eq 10 ] do print "Jon is the best!" (( i += 1 )) done · Bash scripts are pretty easy to come up with, you just write the things you’d type into the interactive shell, and it does those same things for you!
🌐
Simplilearn
simplilearn.com › home › resources › software development › shell scripting in python: a beginner's guide!
Shell Scripting in Python 2024: A Complete Overview!
July 31, 2025 - Learn the basics of shell scripting in Python. This guide covers Python assignment operators and how to use them for effective shell scripting in Python.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Thomas Stringer
trstringer.com › python-in-shell-script
Run Python Code in a Shell Script | Thomas Stringer
January 31, 2021 - So what can you do? Put your Python directly in your shell scripts! How can you do this? Construct your multiline Python string and then pass the ad hoc Python code in with the -c parameter. An example:
🌐
Saralcode
saralcode.com › python › python-shell-tutorial-interpreter-commands-features
Learn to Use Python Shell: A Beginner's Tutorial with ...
Script execution: You can also execute python scripts in the shell by passing the script name as an argument to the python command. For example, python script.py
🌐
Reddit
reddit.com › r/linux › to all experts: shell as a scripting language vs python as a scripting language
r/linux on Reddit: To all experts: Shell as a scripting language vs Python as a scripting language
March 25, 2024 -

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.

🌐
The xonsh shell
xon.sh
The Xonsh Shell — Python-powered shell. Python shell. Python in the shell. Shell in Python. Shell and Python. Python and shell.
The xonsh language provides the shell primitives commonly found in traditional Unix shells, including interaction with standard utilities, pipelines, and input/output streams. Read more → · cd $HOME id $(whoami) > ~/id.txt cat /etc/passwd | grep root $PROMPT = '@ ' The xonsh language is a superset of Python 3, allowing you to execute Python code directly, install and use third-party libraries, import modules, and take advantage of the broader Python ecosystem and tooling.
🌐
LinuxConfig
linuxconfig.org › home › how to use a bash script to run your python scripts
How to Use a Bash Script to Run Your Python Scripts
September 21, 2025 - Learn how to run Python scripts with bash using arguments, virtual environments, and background execution. Boost automation and efficiency.
🌐
Baeldung
baeldung.com › home › scripting › how to call python from a bash script
How to Call Python From a Bash Script | Baeldung on Linux
March 18, 2024 - Let’s grant execute permissions to the Bash script via chmod: ... $ cat ./result.csv 1,Ron,Engineer,False 2,Lin,Engineer,False 3,Tom,Architect,True 4,Mat,Engineer,False 5,Ray,Botanist,False 6,Val,Architect,True · We see the same outcome as before. Alternatively, we can skip saving the contents of the here-document to an intermediate file: $ cat sample_task.sh #!/usr/bin/env bash python3 - ./db.csv << EOF import pandas as pd import numpy as np import sys path_to_file = sys.argv[1] df = pd.read_csv(path_to_file) values, counts = np.unique(df['OCCUPATION'], return_counts=True) x = [values[i] for i in range(len(values)) if counts[i] not in [min(counts), max(counts)]] df['Selected'] = df['OCCUPATION'].isin(x) df.to_csv('./result.csv', index=False, header=False) EOF