Question

Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

===========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

Add a comment
Know the answer?
Add Answer to:
Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash script question.sh that accepts one command line argument which is supposed to be...

    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...

  • write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...

    write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...

  • Write a bash script which pings an IP address 5 times and redirects the output to...

    Write a bash script which pings an IP address 5 times and redirects the output to a text file. Use grep to search the text file and display the line "packets" to stdout. Change the mode of the script to become an executable.

  • 1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories...

    1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. Do not count recursively in subdirectories. Do not call any external Linux utilities such as “ls”. 2.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script....

  • Please write a bash script for the following two questions, thank you.    Write a shell script...

    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...

    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 script that accepts one command line argument 'a' which is an integer between 1 and 50 inclusive. I...

    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...

    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...

    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...

    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).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT