How to create a script inside a program in the terminal?

1

I'm trying to develop a script to automate repetitive tasks I've been doing in the terminal. However. I can only create Scripts for Commands directly in the terminal, not for commands within the program.

How can I create a SH that will work within this program?

    
asked by anonymous 06.10.2017 / 04:16

1 answer

3

I understood your question, but in my opinion your approach is wrong.

I can not see your image and you also did not mention the programming language, but this was already my doubt and I will register here an answer for anyone who might be interested if the language is C or C ++.

You can not create scripts in executables, if you use system calls to execute commands directly.

For this there are some alternatives, the simplest is to use within the executable a call to system() .

A common example would be:

#include <stdlib.h>

int main (int argc, char *argv[])
{
    system(argv[1]);
    return 0;
}

Try passing some argument to the executable, for example:

./binario "ls -l"

There are also other calls that do this with the use of popen() and pclose() , they depend only on stdio.h .

    
06.10.2017 / 09:43