Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run bash commands from txt file

Tags:

file

linux

bash

I have some commands in txt file and I need to execute all them line by line. How could I do it?

like image 962
Андрей Avatar asked Nov 26 '12 15:11

Андрей


People also ask

How do you run a command in a text file?

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.

How do I run a text file in bash?

Using bash We can run our file by using the bash command: $ bash sample. txt Hello World! Note that to run our file with bash, we don't need to use chmod to gain execution permissions.

How do I run a bash command?

In order to run a Bash script on your system, you have to use the “bash” command and specify the script name that you want to execute, with optional arguments. Alternatively, you can use “sh” if your distribution has the sh utility installed.


1 Answers

Just do bash file:

$ cat file  date echo '12*12' | bc  $ bash file Mon Nov 26 15:34:00 GMT 2012 144 

In case of aliases just run bash -i file

No need to worry about file extensions or execution rights.

like image 199
Chris Seymour Avatar answered Sep 21 '22 05:09

Chris Seymour