how can I execute command lines in txt file at Terminal?

Viewed 833

I use MacOS-Catalina 10.15

I have txt file that has command lines about 400 what I want to do is convert or execute this txt file to exec (?) file. Because I don't want to copy and paste to Terminal each of them.

How can I make this file to exec? or How can I call it line by line and run it in terminal?

please help me

thx

1 Answers

Assuming you are using a unix/bash command line. What you are looking for is a bash/sh script.

I would copy and rename your file.txt file to file.sh

You will probably need to make it executable. $ chmod u+x file.sh

You will also want to add #!/bin/bash to the top of your script.

You may need to adjust some syntax but that should be enough to get you rolling. https://www.linux.com/training-tutorials/writing-simple-bash-script/

you could also try just running the file as is $ sh file.txt.

Related