[@computer][~/temp]$bash question.sh 10 | question
1 9 25 49 81
Here is the completed code for this problem. Name your files correctly as mentioned in the question, compile the cpp program, and then execute the command mentioned in question to redirect the input from bash script to the cpp program which displays the squares of each values. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Required bash script
#!/bin/bash
#initializing counter from 1
counter=1
#looping until counter exceeds the value given by first command line argument
while [ $counter -le $1 ]
do
#if counter is an odd number, printing it
if (($counter%2!=0))
then
echo $counter
fi
#advancing counter
((counter++))
done
Required C++ program.
#include<iostream>
using namespace std;
int main(){
//declaring an integer variable
int input;
//looping as long as an integer value is successfully read from standard input
//when there is no input, cin>>input will return false / 0
while(cin>>input){
//displaying square of the input
cout<<input*input<<endl;
}
return 0;
}
Write a bash script question.sh that accepts one command line argument which is supposed to be...
Write a bash script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. It should output a list of integers from 'a' and ending with '1' according to the following iteration rule. ( fx = x/2 if x is even; fx=3x+1 if x is odd )
Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...
Write a C or C++ program A6pc(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...
Write a program in C or a script in bash, called “compare” that takes two numbers on the command line and compares them. The program should print the result of the comparison. Specifically, it should print “<x> is <comparison> <y>”, where <x> is the first number, <y> is the second number and <comparison> is one of “equal to”, “greater than” or “less than”. If the two numbers are equal, the program should have an exit status of zero. The exit...
Write a Perl script that accepts exactly 2 integer arguments where the first argument must be less than the second argument. The script will print a comma separated list of integers starting with the first argument up through the second argument. The last printed value should be the second command line argument not be followed by a comma. The script should also be able to handle the following errorsituations: o incorrect number of arguments o the first...
Unix classes Write a bash script that take in three integer numbers from the command line and print out the sum and the average. Name the script awesum.sh hb1170uxb4:~$ ./awesum.sh 100 200 300 sum: 600 average: 200 hb1170uxb4: ~S
Write a bash shell script to print the number of command line arguments and list of command line arguments 3. 12]
Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...
Write a Bash script called hello that uses command line arguments to allow the user to put two strings after the command name, when the script is being executed. These strings should represent a first and last name. The script should then write out a greeting to the user that includes the first and last name. Here is an example of how the script might work (the first line represents what the user types to launch the script): [user@HAL] hello...
Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...