Pass arguments as a list, see the very first code example in the docs:

import subprocess

subprocess.check_call(['/my/file/path/programname.sh', 'arg1', 'arg2', arg3])

If arg3 is not a string; convert it to string before passing to check_call(): arg3 = str(arg3).

Answer from jfs on Stack Overflow
Discussions

How to pass command line arguments to bash/python script task template
I tried to setup bash/python script template, but I could not get the arguments to pass to the actual script. I added "arg" in the "Args" section, also tried manually entering the CLI args json array ["arg1","arg2"]. but script never pickup those. I also watch the actual command line it launches; I do not see any arguments in the command line. it just like 'bash myscript.sh'. Did I miss anything? Anyone has example with ... More on github.com
🌐 github.com
5
5
January 10, 2025
scripting - bash script to run a python command with arguments in batch - Unix & Linux Stack Exchange
I am trying to automate running a python command with arguments using multiple files (one at a time) and writing the output in output directories with the same name of the input file but without the More on unix.stackexchange.com
🌐 unix.stackexchange.com
shell script - Unable to pass a bash variable as a python argument in bash - Unix & Linux Stack Exchange
For some reason I cannot pass the bash variable $FOLDER as a python argument on the following code. The python script downloads some files from amazon s3. Bash script: #!/bin/bash FOLDER=$(./aws ... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Using a bash script to execute python script with arguments - Stack Overflow
I have been searching for an answer to no avail. I have a python script that I would like to run that has quite a few arguments. It works just fine when I run the command from the terminal, but as soon as I try to put it in a bash script it no longer works. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - Next, we call the Python interpreter to execute the count_filter.py script while providing the file path as an argument: ... $ 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 that only the third and sixth rows get True appended since the Architect occupation occurs with neither the minimum nor maximum frequency. Another option is to embed the Python code explicitly within the Bash script using a here-document.
🌐
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 - The arguments will be accessible within the Python script through the sys.argv list. Here’s an example: #!/bin/bash cd /path/to/python/script/directory python myscript.py $1 $2 $3 · In this script, we run the myscript.py Python script and pass three arguments ($1, $2, and $3) to it.
Find elsewhere
🌐
Medium
medium.com › @nawazmohtashim › call-python-script-from-bash-909afd5248a3
Call Python Script from Bash. In the world of software development… | by Mohd Mohtashim Nawaz | Medium
December 21, 2023 - #!/bin/bash # Call the Python script with arguments python3 myscript.py arg1 arg2 arg3 · Here, arg1, arg2, and arg3 are example arguments that we want to pass to our Python script. To make our Bash script more dynamic, we can pass arguments to the Python script based on user input or other runtime conditions.
🌐
AskPython
askpython.com › home › python and bash integration in linux: a step-by-step guide
Python and Bash Integration in Linux: A Step-by-Step Guide - AskPython
April 10, 2025 - We create a bash script named run_pyscript.sh and pass the argument as python3 followed by the Python file name. ‘python3 ‘calls the python3 interpreter. ‘python_script.py‘ is the name of the Python script to be executed.
🌐
Medium
medium.com › @evaGachirwa › running-python-script-with-arguments-in-the-command-line-93dfa5f10eff
Running Python script with Arguments in the command line | by Eva Mwangi | Medium
April 22, 2023 - Script that adds 3 numbers from CMD optional arguments: -h, --help show this help message and exit --num1 NUM1 Enter third number --num2 NUM2 Enter second number --num3 NUM3 Enter first number · default The default value will be used any time an argument is not provided.
🌐
Humairahmed
humairahmed.com › blog
BASH Shell Scripting: Passing Arguments to a Python Script | HumairAhmed.com
September 1, 2014 - The BASH shell script file takes in a argument(s) and passes the argument(s) to the Python script file. I make the BASH script file an executable with the “chmod +x [BASH script name]” command; I can then put this small utility script in one my path directories as shown by the “echo $PATH” ...
Top answer
1 of 2
5

Replace test with "${filename%.faa}" to get the name of the file with .faa removed. You should also quote "${filename}" to avoid problems in case of filenames with spaces.

#!/bin/sh
for filename in *.faa ; do
    python predict_genome.py \
        --fasta_path /Users/mvalvano/DeepSecE/myruns/"${filename}" \
        --model_location /Users/mvalvano/DeepSecE/model/checkpoint.pt \
        --data_dir data \
        --out_dir myruns/"${filename%.faa}" \
        --save_attn --no_cuda
    done
exit 0

With input files

bar.faa
foo.faa

the script will run

python predict_genome.py --fasta_path /Users/mvalvano/DeepSecE/myruns/bar.faa --model_location /Users/mvalvano/DeepSecE/model/checkpoint.pt --data_dir data --out_dir myruns/bar --save_attn --no_cuda
python predict_genome.py --fasta_path /Users/mvalvano/DeepSecE/myruns/foo.faa --model_location /Users/mvalvano/DeepSecE/model/checkpoint.pt --data_dir data --out_dir myruns/foo --save_attn --no_cuda

Possible problems with this script:

Since you specify --fasta_path /Users/mvalvano/DeepSecE/myruns/"${filename}", your script will only work without error if the current directory is /Users/mvalvano/DeepSecE/myruns/ or if this directory contains at least the same set of *.faa files as the current directory. (*.faa will expand to the file names in the current directory.)

When /Users/mvalvano/DeepSecE/myruns/ is the current directory, the argument --out_dir myruns/foo might expect or create a directory /Users/mvalvano/DeepSecE/myruns/myruns/foo with double myruns.

2 of 2
2

Maybe it would make more sense to write it as:

#! /bin/zsh -
topdir=/Users/mvalvano/DeepSecE
ret=0
for filename in $topdir/myruns/*.faa(N); do
  outdir=$filename:r
  mkdir -p -- $outdir &&
    python -- $topdir/predict_genome.py \
      --fasta_path $filename \
      --model_location $topdir/model/checkpoint.pt \
      --data_dir $topdir/data \
      --out_dir $outdir \
      --save_attn --no_cuda || ret=$?
done
exit $ret

Where we use only absolute paths removing the doubt about what relative paths are relative to.

(here switching to zsh (since that /Users suggests macos) for its :rootname modifier (from csh), its Nullglob qualifier and to remove the need to quote all expansions).

🌐
Stack Overflow
stackoverflow.com › questions › 48834317 › using-a-bash-script-to-execute-python-script-with-arguments › 48834454
Using a bash script to execute python script with arguments - Stack Overflow
Do you get any output? How are you running your script? ... What I meant by doesn't work is I get no output or error message. If I append an echo 'Done' to the bash script, I never see the Done output. ... The above assumes python executable is present in your path.
🌐
Stack Exchange
unix.stackexchange.com › questions › 466543 › how-to-call-a-shell-script-file-with-variable-argument-through-python
bash - How to call a shell script file with variable argument through python - Unix & Linux Stack Exchange
September 3, 2018 - If I keep the actual filename, the shell script file gets executed through second statement. I need to automate this and cannot hardcode the actual filename. Thus, I want if by any chance the variable can be accessed in 2nd statement. import os os.system('sh uploadPDFContentFile.sh Filename1') ... Better use subprocess module. >>> subprocess.run(["ls", "-l"]) # doesn't capture output CompletedProcess(args=['ls', '-l'], returncode=0)
🌐
Home Assistant
community.home-assistant.io › configuration
Shell command - python script in bash script does not receive arguments - Configuration - Home Assistant Community
July 31, 2018 - [SOLVED] simple extra arguement that should not have been there. I have a Hass script that calls a shell command which calls a bash script which calls a python script, which is failing. if I comment everything out of the bash script except the python line, I can trigger it from HASS.
🌐
Reddit
reddit.com › r/bash › bash script to run a python program in background
r/bash on Reddit: Bash script to run a Python program in background
August 1, 2022 -

Hello,

I'm trying to write a bash wrapper script (in Linux) to run a python program in background, allowing the user to logout keeping the script running. I'm trying to do it with nohup. I'm also trying to support a proper ' escape to support space in the arguments (see below).

My goal is that the bash script works like a bash command, passing to the python code all the command line arguments entered by the user.

Here is how I run the python code, without going to background:

$ python3 /scripts/pyprog.py --arg1='argument 1','argument 2','argument 3' --arg2='argument 4','argument 5'

I did something like:

   #!/bin/bash

   NOHUP=$(which nohup)

   ARGS=($*)

   exec "${NOHUP} python3 /scripts/pyprog.py ${ARGS[@]} &"

However, bash tells it cannot run that exec line. I'm clearly missing some point :-) I would very much appreciate any help.

Thanks!

Top answer
1 of 3
3
See screen(1), tmux(1) and loginctl enable-linger ( https://www.freedesktop.org/software/systemd/man/loginctl.html#enable-linger%20USER%E2%80%A6 ) Running detached commands like that is a way to have your machine break and you having no idea how/why. https://wiki.archlinux.org/title/GNU_Screen ; https://wiki.archlinux.org/title/Tmux tmux may be detached from a screen and continue running in the background, then later reattached.
2 of 3
3
OK Couple of things. this :- NOHUP=$(which nohup) is not the right way to do it. /usr/bin/which is an external program and may give different results to those expected. Instead use type -p nohup which uses a bash builtin and will give the exact same answer as bash. Second ARGS=($*) is not the right way to do this either. The arguments will be subject to word splitting. Best to just not mess about with the variables and pass them unchanged using "${@}" Lastly if you put all the arguments to exec in a single set of " marks then it won't find the executable. It is looking for an executable named /usr/bin/nohup python3 /scripts/pyprog.py ${ARGS[@]} & which obviously doesn't exist. So try this instead:- #!/bin/bash output="/tmp/output" exec "$(type -p nohup)" /scripts/pyprog.py "${@}" > "$output" 2>&1 & Note I didn't put 'python3' in there at all. The right fix for that part is to put `` #!/usr/bin/env python3 ``` as the first line of your python script. also you probably want to capture stdout and stderr from your python script (so I redirected them to a file in /tmp). You may also want to take care of stdin, but I didn't bother.