I\'m using VI editor in shell script in mobaXterms. Please screenshot the whole
ID: 3878739 • Letter: I
Question
I'm using VI editor in shell script in mobaXterms. Please screenshot the whole thing if possible. Thank you
Demonstrate the ability to use text editors in the shell. Demonstrate the ability to create and execute shell scripts. Demonstrate the ability to create and compile multi-file C++ programs. Demonstrate the ability to access the command line arguments from within a C++ program. Demonstrate proficiency in logging your console output using the “screen –L” command
Document all the shell work done to complete the assignment using the “screen –L” program or putty logging. This will keep a log of all your shell work. You will need to turn in the output files from “screen –L”/putty.
With console logging enabled, write a program that consists of two C++ source files. The first file contains the main() routine and the second file contains a C++ procedure
From within main(), you must display the count of command line arguments to stdout. Further, you must display the value of each command line argument to stdout. Finally, you must call the procedure that is defined in the second file.
From within the procedure defined in the second file, you must display a log message that states you are inside the procedure. This log message must be sent to stderr.
You are then to create a shell script for compiling your code. The script will individually compile each file and generate the intermediate object file. Once the object files are created, the script will call the linker and link the object files into an executable. Your shell script should echo what it is doing at each step to stdou
You are then to create a second shell script that will run your program several times with varying command line arguments. Each time you call your program, you should append the stdout to an output file called stdout.log and you should append the stderr to an output file called stderr.log. Your shell script should echo what it is doing at each step to stdout.
Explanation / Answer
create two file main.cpp and fun.cpp. copy the code into them.
use sh compile.sh to compile the code.
use sh run.sh to run the code.
-------------------------------------------------------------------------------------------------------------------------------
main.cpp:
#include <iostream>
using namespace std;
/*funtion declarartion*/
void test();
int main(int argc, char **argv)
{
int i;
cout << "Nuber of command line argumnet passed : " << argc << " ";
for( i = 0; i < argc; i++)
{
cout << "Argument " << i+1 << " : " << argv[i] << " ";
}
/*Calling the test function*/
test();
}
fun.cpp
#include <iostream>
using namespace std;
void test()
{
cerr << "Entered into the test function ";
}
compile.sh
echo "compiling the main.cpp"
g++ -c main.cpp -o main.o
echo "compiling the fun.cpp"
g++ -c fun.cpp -o fun.o
echo "generating binary outbin by linking main.o and fun.o"
g++ main.o fun.o -o outbin
run.sh
echo "excuting the outbin with argument rohit and 1"
./outbin rohit 1 1>> stdout.log 2>> stderr.log
echo "excuting the outbin with argument Om Nama shivay"
./outbin Om Nama shivay 1>> stdout.log 2>> stderr.log
---------------------------------------------------------------------------------------------------------------------------------
output screen shot:
1$ cat stderr.log
Entered into the test function
Entered into the test function
$ cat stdout.log
Nuber of command line argumnet passed : 3
Argument 1 : ./outbin
Argument 2 : rohit
Argument 3 : 1
Nuber of command line argumnet passed : 4
Argument 1 : ./outbin
Argument 2 : Om
Argument 3 : Nama
Argument 4 : shivay