Write a script that will produce the output as the following runs:
bash-3.00$ isNumPN 5
5 number is positive
bash-3.00$ isNumPN -45
-45 number is negative
bash-3.00$ isNumPN
./isnumPN : You must give/supply one integers
bash-3.00$ isNumPN 0
0 number is negative
===========Bash Script=============
#!/bin/bash
# $# gives the number of arguments
# case when the no of arguments are not 1
if [ "$#" -ne 1 ]; then
echo "You must give/supply one integers"
# if number is negative
elif [ $1 -lt 0 ]
then
echo "$1 number is negative"
# if number is positive
elif [ $1 -gt 0 ]
then
echo "$1 number is positive"
# if number is 0
else
echo "$1 number is negative"
fi
Sample Output
0 number is negative
===============C language=====================
#include<stdio.h>
int main(int argc, char *argv[])
{
// if no of arguments is not 1
if( argc != 2 )
{
printf("You must give/supply one integers");
// exit the program
exit(0);
}
// convert string into int using atoi() function
int n = atoi( argv[1] );
// if number is negative
if( n <= 0 )
printf("%d is negative", n);
// if number is positive
else
printf("%d is positive", n);
return 0;
}
Sample Output
0 number is negative
Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...
Write a bash script question.sh that accepts one command line argument which is supposed to be a positive integer n. The script should print all odd integers from 1 through n. Write a C or C++ program question.c(pp) to read from stdin as many integers as there are available and then print the squares of all these integers. You should test your code by “./question.sh <n> | ./question” assuming the compiled C/C++ program is question. See the following for a...
Please write a bash script for the following two questions, thank you. Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs to take two inputs like “6-1.sh a b”, and outputs the result of “ab”. Note: You need to implement it, DO NOT use the exponentiation operation provided by the Linux. Write a shell script “6-2.sh” to calculate the factorial of a number using while loop. This script needs to take one input...
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 bash shell script called direct.sh. This script will take an arbitrary number of command line arguments. Your script should create directories starting with the first argument, then the second directory inside the first one, and then the next one inside the second one, and so on.
Write a Bash script that removes all zero length ordinary files in the directory (including those in the sub-directories at all levels) passed as an optional argument. If you do not specify the directory argument, the script uses the current working directory as the default argument. This problem is for practicing bash programming skills. Though there is an easier way to achieve the goal with find, find is not allowed to appear in your bash script. Post the screenshot of...
write a bash script that will take one or more directory names as arguments and count the number of .txt files under each one (that is the number of .txt files in each subdirectory, subdirectories and so on).
in Linux, BASH Shell Write a while loop script called count that counts and prints the numbers 0 thru 9 without issuing a new line after each output.
Write a bash script that prompts a user with a menu of choices: Get the total number of shell files from the current directory Get the total size of all the shell files from the current directory Get the total number of empty files in the system from the current directory Each option must be its own specific function. linux only
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...
LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...