Run text file as commands in Bash
Solution 1:
you can make a shell script with those commands, and then chmod +x <scriptname.sh>
, and then just run it by
./scriptname.sh
Its very simple to write a bash script
Mockup sh file:
#!/bin/sh
sudo command1
sudo command2
.
.
.
sudo commandn
Solution 2:
you can also just run it with a shell, for example:
bash example.txt
sh example.txt
Solution 3:
Execute
. example.txt
That does exactly what you ask for, without setting an executable flag on the file or running an extra bash instance.
For a detailed explanation see e.g. https://unix.stackexchange.com/questions/43882/what-is-the-difference-between-sourcing-or-source-and-executing-a-file-i