Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use the bash script to Write a script view.sh that takes one or more command line arguments. Each argument must be the name of a

use the bash script to Write a script view.sh that takes one or more command line arguments. Each argument must be the name of a readable file. For each argument, view.sh should check whether this is a file that was compressed using gzip. If so, it should uncompress it using gunzip and display the result using cat. (You may also explore whether gunzip can display its output directly, without using cat as a helper.) If the file was not compressed using gzip, the file should be displayed without decompressing it. There are two important requirements for view.sh:While the default behaviour of gunzip is to delete the file.gz file it is given and create the uncompressed file file from it, view.sh is not allowed to do this. There are many ways to achieve this. One of them is to copy the file to be decompressed into the /tmp directory, decompress it there, display it, and delete it from /tmp. Second, view.sh should display only the contents of the files that were passed to it. For each file that cannot be read, it should print an error message ERROR: Cannot read file xxx, where xxx is the file in question. No other output must be produced. Most of this question should be straightforward. There are two parts that require some creativity: How to check whether a file is compressed? gunzip can help you with that. Just try to run it on the given file. If the file is a gzipped file, this just works. Otherwise, it fails and gunzip lets you know via its exit code. The previous suggestion leads to another wrinkle: when gunzip fails, it happily informs us with an error message, but view.sh is not allowed to produce any output other than its own error messages. You need to figure out how to silence gunzip. man gunzip and a careful read of that manpage and a Google search for /dev/null lead you to two possible ways to do this.

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

Students also viewed these Databases questions