Question: What to do Create a shell script called A4-$USER.bash that implements what is requested below. The requirements are broken into Part 1 Requirements and Part

What to do

  • Create a shell script called A4-$USER.bash that implements what is requested below.
  • The requirements are broken into Part 1 Requirements and Part 2 Requirements in an attempt to help the students break the problem into two manageable parts.
  • You will submit only one script A4-$USER.bash that implements both Part 1 and Part 2 requirements.
  • Test that your script correctly implements the required functionality.

Part 1 Requirements

Your script will receive no arguments. The first task of the script is to present a prompt like this

$USER-A4-

There should be a space after the dash. To allow the user to enter commands in the same line as the prompt, use printf instead of echo (look up the man page for printf for more information).

printf something

For Part 1, there are only two commands your script must handle. If any other command is entered, the script should reply

Unrecognized command.

and then present the prompt again. The two commands are:

  1. quit - The script must exit.
  2. setdb inputfile.txt

If inputfile.txt exists, and is readable, then your script must respond with

Database set to inputfile.txt

If the input file does not exist, your script must respond

File inputfile.txt does not exist.

If the input file exists, but is not readable, your script must respond

File inputfile.txt is not readable.

If no input file is provided, your script must respond

Missing Argument.

Your script should be able to handle a full path filename, such as

/home/dv35/A4/inputfile.txt

If more than one input file is provided, your script must respond

Database set to inputfile.txt

Extra arguments ignored.

Following is a sample run that shows the expected behavior of the script.

dv35@tux2:~/A4$ ./A4.bash

dv35-A4-hi

Unrecognized command.

dv35-A4- setbb

Unrecognized command.

dv35-A4- setdb

Missing Argument.

dv35-A4- setdb notExistentFile.txt

File notExistentFile.txt does not exist.

dv35-A4- setdb notReadable.txt

File notReadable.txt is not readable.

dv35-A4- setdb input.txt

Database set to input.txt

dv35-A4- setdb input.txt and something else

Database set to input.txt

Extra arguments ignored.

dv35-A4- quit

dv35@tux2:~/A4$

Part 2 Requirements

Your script will need to be extended to support one additional command

  1. printdb

If the database has not been set by a previous setdb command, your script must respond

Database has not been set.

If the database has been set, the script should investigate the contents of the file and recognize which lines in the file are well-formed and which ones are not. The script must print

Well Formed Lines:

followed by all lines from the database file showing the first and last names of people like in this example

{first:dimitra last:vista}

{first:spiros last:mancoridis}

Your script should ignore lines that are not well-formed. Your script should not output lines that are not well-formed.

Following is a sample run that shows the expected behavior of the script.

Suppose the database file contains these lines

{first:dimitra last:vista}

{first:spiros last:mancoridis}

{not the right format}

{first:Grace last:Kelly}

{Hank R Chief}

Hello World.

The sample run given the database input file is:

dv35@tux2:~/A4$ ./A4.bash

dv35-A4-setdb input.txt

Database set to input.txt

dv35-A4- printdb

Well Formed Lines:

{"first":dimitra "last":vista}

{"first":spiros "last":mancoridis}

dv35-A4- quit

dv35@tux2:~/A4$

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!