run python file list with shell script

Asked

Viewed 95 times

0

My code:

#!/bin/bash

scriptspy =(
    '/scs/sp1.py',
    '/scs/sp2.py',
    '/scs/sp3.py',
    '/scs/sp4.py',
    '/scs/spweb.py',
    '/scs/sp11.py',
    '/scs/spservice.py',
    ....
)

for i in scriptspy;
  do python3.7 $i;
done

My goal is to run a list of files that have python in the directory and do not need to run one by one individually with python3.7 sp1.py

Note: I can’t run all the files. py in the directory, I need to pass a list to the loop with their name, or a list that cannot be executed, I have in all 28 want to run and 3 that I do not want to run.

1 answer

1


Your code was almost right.

#!/bin/bash

scriptspy=(
    '/scs/sp1.py',
    '/scs/sp2.py',
    '/scs/sp3.py',
    '/scs/sp4.py',
    '/scs/spweb.py',
    '/scs/sp11.py',
    '/scs/spservice.py'
)

for i in ${scriptspy[*]};
  do python3.7 $i;
done

Browser other questions tagged

You are not signed in. Login or sign up in order to post.