Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run text files in terminal

Does anyone know if there's a way to run automatically in shell a list of commands (from a text file)?

I need to run a lot of scripts (around 1000). The scripts are in python and take 2 arguments each (dir_#, and sample#)

The text file I've 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 would expect that passing this text file as argument to a command in terminal, could do the job automatically...

Thanks in advance,

peixe

like image 803
peixe Avatar asked Jul 01 '11 09:07

peixe


People also ask

How do I run a text file in Linux terminal?

Right click on the text file, select properties, select permission, mark the "Let this file be executed" text box. Now you can execute it just by double clicking on the file. You can also do it from the console like this: sh ec2-env-setup.

How do I run a text file in command prompt?

In your case you can drag file from your where your are to command prompt. Or Using CD you can reach out where your file is saved within your command prompt. Fire up file. bat on your command prompt will execute whatever batch programming is written on that file.


2 Answers

That's called a "shell script."

Add this to the top of your file:

#!/bin/sh

Then execute this command:

chmod +x filename

Then execute it like a program:

./filename

Alternately, you can execute the shell directly, telling it to execute the commands in your file:

sh -e filename
like image 61
Flimzy Avatar answered Nov 16 '22 00:11

Flimzy


Also, you can run a shell file by:

source filename
like image 24
Noon Avatar answered Nov 16 '22 00:11

Noon