Terminal (OS X), command queue from file

I want to execute a command queue in a Mac terminal. Is it possible to prepare a file containing a number of commands and send the file through the terminal? For example ... command.txt contains several commands: one per line:

./executable_file -f sub_a 100 ./executable_file -f sub_b 100 ./executable_file -f sub_c 100 ./executable_file -f sub_d 100 ... 

How can i do this?

+4
source share
3 answers

I might misunderstand you, but that sounds like a typical case of a shell script file.

Create a file "myscript.sh", add your commands to it. Make the first line

 #!/bin/sh 

tell OS X what to do with the file. Then mark it executable (chmod + x myscript.sh) and run it on. /myscript.sh.

That should do the trick.

+7
source

You can do this with a shell script that contains these commands. Typically, the extension will be .sh (so name it commands.sh instead of commands.txt ).

Then you can run it using bash commands.sh .

In addition, if the first line of your file is #!/bin/bash , and if you make it executable (for example, via chmod 755 commands.sh ), you can execute this file directly: ./commands.sh .

Other lines starting with # (or anything after # in the line) will provide comments if you need to.

Here are some guides:

There are other shells besides bash, but bash is used by default for OSX (same as /bin/sh ): this is what you are already using in the terminal. This is also the default for the number of Linux distributions.

+2
source

Yes. This is called a shell script and is a function of your shell (perhaps bash if you haven't changed it), not Terminal.app itself.

There are many shell related resources on the Internet, but in the basic form, just run the file using the line

 #!/bin/bash 

make it executable using the chmod +x commands.txt and place your commands in a file in the order in which you want to run them. (Note that using the .txt extension, while completely legal, can be a bit confusing).

+1
source

Source: https://habr.com/ru/post/1387191/


All Articles