Running text files in the terminal

Does anyone know if there is a way to start a list of commands (from a text file) automatically in the shell?

I need to run many scripts (about 1000). The scripts are in python and take 2 arguments each (dir_ # and sample #)

The text file I made looks like this ...

python /home/name/scripts/get_info.py dir_1 sample1 python /home/name/scripts/get_info.py dir_2 sample2 python /home/name/scripts/get_info.py dir_3 sample3 python /home/name/scripts/get_info.py dir_4 sample4 ... 

So, I expect that passing this text file as an argument to a command in the terminal can automatically do the job ...

Thanks in advance,

Peixe

+7
source share
4 answers

This is called a shell script. "

Add this to the top of the file:

 #!/bin/sh 

Then run the following command:

 chmod +x filename 

Then execute it as a program:

 ./filename 

Alternatively, you can directly launch the shell by telling it to execute commands in your file:

 sh -e filename 
+16
source

Or make an executable file:

 chmod u+x thefile ./thefile 

or run it as an argument to sh:

 sh thefile 
+3
source

You can write a shell script:

 #! /bin/sh python /home/name/scripts/get_info.py dir_1 sample1 python /home/name/scripts/get_info.py dir_2 sample2 python /home/name/scripts/get_info.py dir_3 sample3 python /home/name/scripts/get_info.py dir_4 sample4 ... 
+2
source

Alternatively, you can run the shell file:

 source filename 
+1
source

All Articles