Run bash commands from txt file
LinuxFileBashLinux Problem Overview
I have some commands in txt file and I need to execute all them line by line. How could I do it?
Linux Solutions
Solution 1 - Linux
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.
Solution 2 - Linux
In a Terminal just type:
bash path/to/my/file.txt
And you will get each lines executed.
Solution 3 - Linux
just change the extension of the file to .sh
add /bin/bash at starting of the file
change the permission of the file to executable
than simply run ./filename.sh command in command line. all the commands in the file will be executed
Solution 4 - Linux
Change the extension to .sh and for the first line #!/usr/bin/env bash
and as someone else said chmod +x