Create a shell script to run the python file multiple times

Create a shell script to run the python file multiple times

Implementation environment

This directory configuration example

home └── user1   └── src    ├─── test.sh    └─── test.py

procedure

  1. Prepare the python file you want to run
  2. Create a shell script
  3. Run the shell script

1. Prepare the python file you want to run

test.py

test.py


# -*- coding: utf-8 -*-

print u'Hello'.encode('UTF-8')

2. Create a shell script

test.sh

test.sh


#!/bin/sh

ARRAY=(1 2 3 4)

for num in ${ARRAY[@]}; do
    /usr/bin/python /home/user1/src/test.py
    echo $num"This is the second loop"
done

3. Run the shell script

Execute while specifying the shell script to be started by the following command Command: `` `bash /home/user1/src/test.sh```

Execution result example

result.png

Recommended Posts

Create a shell script to run the python file multiple times
A memorandum to run a python script in a bat file
Python script to create a JSON file from a CSV file
How to run a Python program from within a shell script
Run the Python interpreter in a script
Script to create a Mac dictionary file
How to run a Maya Python script
Conditional branch due to the existence of a shell script file
How to create a JSON file in Python
Create a shortcut to run a Python file in VScode on your terminal
When running a Python shell from Electron, pass multiple arguments to run Python.
Template of python script to read the contents of the file
Create a plugin to run Python Doctest in Vim (2)
Create a plugin to run Python Doctest in Vim (1)
Zip-compress any file with the [shell] command to create a file and delete the original file.
Create a python script to check if the link at the specified URL is valid 2
Create a python script to check if the link at the specified URL is valid
How to use NUITKA-Utilities hinted-compilation to easily create an executable file from a Python script
[python] Change the image file name to a serial number
How to run a Python file at a Windows 10 command prompt
A Python script that saves a clipboard (GTK) image to a file.
[Python, shell script, team development] Create a nifty Git repository
Change the standard output destination to a file in Python
Probably the easiest way to create a pdf with Python3
Create a binary file in Python
5 Ways to Create a Python Chatbot
How to create a config file
[OCI] Python script to get the IP address of a compute instance in Cloud Shell
I tried to create a Python script to get the value of a cell in Microsoft Excel
After calling the Shell file on Python, convert CSV to Parquet.
A story about trying to run multiple python versions (Mac edition)
Python vba to create a date string for creating a file name
A script that returns 0, 1 attached to the first Python prime number
[Ubuntu] How to execute a shell script
Create a deb file from a python package
[GPS] Create a kml file in Python
Creating a shell script to write a diary
Have Alexa run Python to give you a sense of the future
Test & Debug Tips: Create a file of the specified size in Python
A shell script to make sure you don't forget the pipenv shell again
I made a program to check the size of a file in Python
What is the fastest way to create a reverse dictionary in python?
Script python file
[Python] List Comprehension Various ways to create a list
Run a Python script from a C # GUI application
Edit Excel from Python to create a PivotTable
How to read a CSV file with Python 2/3
Create a GIF file using Pillow in Python
How to create a Python virtual environment (venv)
I want to create a window in Python
Create a New Todoist Task from Python Script
Steps to create a Twitter bot with python
Save the object to a file with pickle
Export Python3 version OpenCV KeyPoint to a file
Run a Python file from html using Django
Create a Photoshop format file (.psd) with python
Launch a shell while a Python script is running
A python amateur tries to summarize the list ②
Create a MIDI file in Python using pretty_midi
I want to write to a file with Python
Run a python script from excel (using xlwings)