数据库考试

数据库考试代考 Create a shell script called A4-$USER.bashthat implements what is requested below. The requirements are broken into…

What to do

  • Create a shell script called A4-$USER.bashthat 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.bashthat 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$