Question

In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE...

  • In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE statement.
  • The if_then_else.sh script will
  • Use one command line argument, which will be a number between 1 and 10
  • Assign the value of the first argument to a local variable called NUM. HINT: Look at line 5 in the example screenshot for arguments.sh
  • Use one IF THEN ELSE statement to compare the value of NUM
  • If the number is less than 5, display the message "The number is less than 5"
  • If the number is 5 or greater, display the message "The number is 5 or greater"
  • When running
  • Here are some hints
  • Watching the video about IF THEN ELSE/ELIF Statement may be helpful
  • The IF THEN ELSE statement has the form

If [ $NUM   operator   number ]

then

            echo "<message>"

else

            echo "<message>"

fi

  • There must be a space after each element to avoid syntax error messages; i.e. there must be a space after the bracket, $NUM, operator and number
  • Decide which integer operator to use. Look at the slide "Integer Operators"
  • Decide what the value of number should be.
  • Decide which message should go where
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program code to copy:-

# Assign the value of the first argument to a local variable called NUM
NUM=$1
#compare the value of NUM with 5 using -ge operator(means greater than and equal to)
if [ $NUM -ge 5 ]
then
    echo "The number is 5 or greater"

else
    echo "The number is less than 5"
fi

Screenshot of script:-

Screenshot of output:-

$sh if_then_else.sh 4

$sh if_then_else.sh 7

Add a comment
Know the answer?
Add Answer to:
In this exercise, you will create a script called if_then_else.sh that uses an IF THEN ELSE...
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
  • In this exercise, you will create a script called file_ops.sh that uses the various file operators...

    In this exercise, you will create a script called file_ops.sh that uses the various file operators The file_ops.sh script will Use one command line argument Use four IF THEN statement to compare the first command line argument Determine which file operators to use that produces the following output when the script run with the arguments shown WARNING: In the IF THEN statements, to avoid syntax error messages, there must be a space before and after each bracket and also between...

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

  •  Write a Perl script that accepts exactly 2 integer arguments where the first argument must...

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

  • This exercise is also from C++ How do I even figure this out? please help me...

    This exercise is also from C++ How do I even figure this out? please help me solve so I can get the answer correctly! Question 28 10 pts (SHORT ANSWER) Define a function named findEvenOrOdd that has 1 int parameter: num. When the function is called, it should use an if/else statement -OR- conditional expression to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is...

  • python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function...

    python programming X Canvas 4 → XCO Question 26 10 pts (SHORT ANSWER) Define a function named find_even_odd that has 1 parameter: num. When the function is called, it should use an if/else statement to determine whether the variable num is an even or odd number and display appropriate message as follows: • If the value in num is an even number, the progr will output the message: "XX is an EVEN number", where XX is the value in the...

  • Need help please! Question 1: you must use if /else statement to receive credit for this...

    Need help please! Question 1: you must use if /else statement to receive credit for this question Write a MATLAB script to prompt the user to enter the value of t and use if /else statement to calculate f(t): 0. ift 0.5 f)2t2, if 0.5<t<1 4t. for all other t Test your code with different values of t. Question2: you must use switch/case to receive credit for this question Create a script to prompt the user to enter TWO numbers....

  • Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file...

    Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Create simple python beginners code that outputs a proverb upon request. Find 7 proverbs, wise sayings,...

    Create simple python beginners code that outputs a proverb upon request. Find 7 proverbs, wise sayings, or quotes Store your proverbs in an if-elif-else decision structure (see below) Your application should locate the corresponding proverb Print the proverb and its explanation to the screen, each on a separate line. Write a “welcome” message that greets the user and explains how the program works Ask your user to enter a positive integer. Echo back the user’s choice – for example, “You...

  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

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
ADVERTISEMENT