Passing parameters to Bash scripts (on Linux or Windows)

Spread the word!


We want to pass parameters to a bash script (more flags with no value, but also variables with user defined values, no matter in which order we provide them). According to the input parameters, this bash script can call other python scripts and pass them other parameters. It’s quite easy to implement it, but I find it useful to keep a ready-to-use code (which is the reason why I’m writing this post…).


From the command line, we want to write (in Linux syntax):

If you need to run the bash script on Windows, install Cygwin first and add the bin folder (e.g. C:\cygwin64\bin) to the PATH variable. Then, you can run a similar terminal line on Windows:

In the bash  script, there are some stardard sections, dealing with our parameters: initialization, parameter fetching and conditional statemets to check what you have.

Afterwards, you should handle the arguments in your Python scripts. E.g. call the first passed argument with:

My intention here is to provide a specific basic usage, but much more could still be said.

Be the first to comment

Leave a Reply

Your email address will not be published.