Saturday, October 30, 2021

[SOLVED] How to Creat bash script for this

Issue

I'm using termux app to compile my c/c++ code. Typing g++ [file.cpp] -o [file] and then ./[file] on mobile every time feels hard to me. can anyone tell me Linux script that runs with one simple command/word/keyword (something like "alias") to compile and execute the file?


Solution

If you want specifically a bash script for that, try

g++ $1.cpp -o $1
./$1

Save this as any file name you like, such as run. Then make it executable by typing chmod +x run in your terminal.

Now let's say you have a test.cpp with the content below

#include <iostream>
int main() {
    std::cout << "Testing...";
    return 0;
}

You can simply type ./run test in your terminal and the result should be

Testing...


Answered By - Kuwach