LoginSignup
46
45

More than 5 years have passed since last update.

シェルスクリプトを作成してpythonファイルを複数回動かす

Last updated at Posted at 2016-10-17

シェルスクリプトを作成してpythonファイルを複数回動かす

実施環境

  • OS:Ubuntu 14.04.4 LTS

今回のディレクトリ構成例

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

手順

  1. 動かしたいpythonファイルを用意する
  2. シェルスクリプトを作成する
  3. シェルスクリプトを実行する

1. 動かしたいpythonファイルを用意する

test.py

test.py
# -*- coding: utf-8 -*-

print u'こんにちは'.encode('UTF-8')

2. シェルスクリプトを作成する

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"回目のループです"
done

3. シェルスクリプトを実行する

下記のコマンドで起動するシェルスクリプトを指定しつつ実行する
コマンド:bash /home/user1/src/test.sh

実行結果例

result.png

46
45
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
46
45