Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1)Write a Bash shell script named stars.sh that a. Take 1 number as an argument and prints a triangle of asterisks that is left-aligned. For

1)Write a Bash shell script named stars.sh that

a. Take 1 number as an argument and prints a triangle of asterisks that is left-aligned. For

example, if the argument is 4 prints the following:

*

**

***

****

b. If there is not exactly 1 argument, or the argument is not an integer, or the integer is less

than 1, print an error message and exit

c. Hint: Use for loops

2) Write a Bash shell script named calc.sh that

a. Performs addition (+), subtraction (-), multiplication (x), and integer division (/) math

operations.

b. Takes in 2 operands and 1 operator and prints the result. Example: calc.sh 5 + 3 would

print 8 and calc.sh 9 / 2 would print 4

c. If there are not exactly 3 arguments, or the second argument is not one of the operators in

part (a), or first or third argument is not an integer, print an error message and exit

d. If operator is division (/) and second operand is 0, then print error message error: cannot

divide by 0 and exit

e. Hint: Use case statement

3) Write a Bash shell script named hello.sh that

a. Prints different messages depending on the time of day when it is executed

b. Print Hello , it is

and noon (exclusive)

c. Print Hello , it is

and 6pm (exclusive)

d. Print Hello , it is

midnight (exclusive)

e. Print Hello , it is

and 6am (exclusive)

f. Replace with the actual username of the user running the script

g. Replace

h. This script should not take any argument, so if there is any argument supplied print an error

message and exit

i. Hint: Use whoami and date commands

4) Write a Bash shell script named shiftCase.sh that

a. Convert the supplied string arguments to all uppercase or all lowercase depending on the

supplied flag

b. If the flag is -l performs the lowercase conversion and print the result to screen

c. If the flag is -u performs the uppercase conversion and print the result to screen

CPSC-254 Fall 2017 Prof. Thomas Nguyen Assignment #4 pg. 2

d. Only alphabetic characters are converted. Non-alphabetic characters (such as numbers,

punctuation marks, etc.) are not affected.

e. Exactly one of two options (-l and -u) must be specified. If none are specified, or both are

specified, or something other than -l or -u is specified, print an error message and exit.

f. If there is no argument specified, then print an error message and exit

g. If there is more than one argument, convert each argument and print each result on a

separate line

h. Hint: Use getopts and tr commands

5) Write a Bash shell script named getAbsPath.sh that does the following:

a. Take 1 or more relative paths to files or directories as arguments and print the

corresponding absolute paths

b. For each argument given on the command line, print the argument as is, followed by => ,

followed by the corresponding absolute path of the argument

c. If argument is a file or directory that doesnt exist, print does not exist after =>

d. If argument is already an absolute path, print already absolute path after =>

e. If argument is a symbolic link you do not have to follow the link, just determine the absolute

path of the symbolic link

f. If there is no argument, print an error message and exit

g. Important: You can NOT use realpath or readlink commands.

h. Hint: Use pwd and basename and dirname commands

need 5 ASCII text files, one for each script. The files must be ready for execution, i.e.

requiring no changes (other than setting the execute permission bits).

use the following function to determine whether something is a valid integer.

isInteger() {

if [[ $1 =~ ^[+-]?[0-9]+$ ]]; then

return 0

else

return 1

fi

}

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions