Run text file as commands in Bash Run text file as commands in Bash linux linux

Run text file as commands in Bash


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/shsudo command1sudo command2 ...sudo commandn


you can also just run it with a shell, for example:

bash example.txtsh example.txt


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