Question

In: Computer Science

LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...

LINUX

In Linux command line write a shell script ex1.sh that uses IF THEN to

Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command)

If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember you want to use the Integer Operators like –lt.)

Run 'cat ex1.sh'

Run 'sh ex1.sh' and enter 3 when prompted

Run 'sh ex1.sh' and enter 5 when prompted

Run 'sh ex1.sh' and enter 7 when prompted

Solutions

Expert Solution

Shell Script: ex1.sh

#!/bin/bash

# Prompting user to enter a number
echo -n " Enter a number between 1 and 10: "

# Reading a number
read NUM

# If condition to check for number that is less than 5
if [ $NUM -lt 5 ]; then

    echo "\n The number is less than 5 \n"

else
  
    # Number entered is greater than 5
    echo "\n The number is greater than or equal to 5 \n"

fi

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument...
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake. If there is an easy way to use a loop to get all arguments, use it? a. Display the source code in an editor (#4-1) b. Execute your script in the terminal, and display the command and the result (#4-2)
Write a script named countmatches that expects at least two arguments on the command line. The...
Write a script named countmatches that expects at least two arguments on the command line. The first argument is the pathname of a dna file containing a valid DNA string with no newline characters or white space characters of any kind within it. (It will be terminated with a newline character.) This dna file contains nothing but a sequence of the bases a, c, g, and t in any order. The remaining arguments are strings containing only the bases a,...
Question #11. Write a script that uses the menu function to prompt the user to select...
Question #11. Write a script that uses the menu function to prompt the user to select the current day of the week. Then use the menu function to prompt the user to select their favorite day of the week. Print a message telling the user how many days it will be until their favorite day. The output must include the current day, the favorite day, and the number of days until the favorite day. Debug your programming by running it...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
USING COMMAND PROMPT ON LINUX. show how... Linux Users, Groups, and Permissions Lab Objective: Understand how...
USING COMMAND PROMPT ON LINUX. show how... Linux Users, Groups, and Permissions Lab Objective: Understand how to create user accounts Understand how to create group accounts Creating good password policies Understanding permissions and file sharing Setup: You will need a Ubuntu Server VM Walk Through: You are a system administrator who has been tasked to create user accounts for new users on your system. You can pick whatever theme you like as long as there are protagonist and antagonist users:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT