Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create 3 shell scripts, one for each of the following tasks. Put each one in a new file, and name them script1.sh, script2.sh, and script3.sh.

Create 3 shell scripts, one for each of the following tasks. Put each one in a new file, and name them script1.sh, script2.sh, and script3.sh. Make sure to run the command chmod 777 script1.sh script2.sh script3.sh to give full permissions to read, write, and execute each script, and then submit each of the 3 files along with this assignment using handin

script1.sh : Write a shell script that takes 2 arguments, the first one a filename and the second one a number. The script should print the filename to the screen x times using a loop (where x is the number of characters in the filename), and then should check to see if the second argument is a number less than 0. If it is, print out the message Negative. If it is not, print out the message Positive. Separate the looped messages from the last message you display with a blank line. HINT: There are several ways to get the length of a string, so do some searching to find one to use. As an example, if you run your script using the command ./script1.sh test.sh 46 , your script should display to the screen the following:

test.sh

test.sh

test.sh

test.sh

Positive

b) script2.sh : Write a shell script that prints out the numbers of the Fibonacci series. This series of numbers is one where every number is the sum of the previous two numbers before it. For example, the first 10 number of the series is {0, 1, 1, 2, 3, 5, 8, 13, 21, 34}. The series is infinite, so assume that one command line argument is given to your script which is the total number of Fibonacci numbers to display. If a 1 is given, have it print off just the first number. If a 2 is given, have it just print off the first two numbers. If a 3 or bigger is given, have it print off the first two numbers, then have your code calculate the rest automatically. Assume that a logical number will always be given to you (dont worry about checking to see if the number is bigger than 0, for example).

As an example, if you run your script using the command ./script2.sh 5 , your script should display to the screen the following:

0

1

1

2

3

) script3.sh : Write a shell script which asks the user to enter two numbers, the first one a being smaller than the second number. If the first number entered is bigger than the second, print off the message The first number must be smaller than the second! and stop the script. If the first number is smaller than the second, have the script list all ordinary files with sizes between a certain range in a given directory. Assume that the directory is specified when the script is run as the first and only command line argument. Display only the files between the minimum size (in number of bytes) and the maximum size (in number of bytes) that the user entered in (minimum size is the first number, and maximum size is the second number). Thus, your script must output under the directory (specified by the first argument $1) all the files whose sizes are no less than the minimum size (the smaller number) and no greater than the maximum size (the bigger number) in bytes. Each files name must be displayed along with its size on one line. Only consider files in the directory given, not in any subdirectories. See the example below to see how to have your program display information.

As an example, suppose in the directory /opt/new/ there are four ordinary files: a.txt, b.txt, c.txt and d.txt, and their sizes are 3, 9, 14 and 20 bytes, respectively. If you run your script using the command ./script3.sh /opt/new/ , and you enter in the values 5 and 15 when asked, you should get the exact same following output:

Enter a number: 5

Enter in a bigger number: 15

The files in /opt/new/ that are between 5 and 15 bytes are the following:

b.txt is 9 bytes

c.txt is 14 bytes

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

=+ 5. Do Europeans work more or fewer hours than Americans?

Answered: 1 week ago