Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

UNIX Shell Programming This script dirtree.csh which prints a directory tree has some errors: #!/bin/tcsh -f if($#argv == 0) then set thisdir=. else set thisdir=$argv[1]

UNIX Shell Programming

This script dirtree.csh which prints a directory tree has some errors:

#!/bin/tcsh -f

if($#argv == 0) then

set thisdir="."

else

set thisdir=$argv[1]

endif

if($?TREEPREFIX) then

set prefix="$TREEPREFIX"

else

set prefix=""

endif

echo "$prefix|"

set filelist=`ls -A $thisdir`

foreach file ($filelist)

echo "${prefix}|------${file}"

if(-d "$thisdir/$file") then

if($file == $filelist[$#filelist]) then

setenv TREEPREFIX "${prefix} "

else

setenv TREEPREFIX "${prefix}| "

endif

echo $0 "$thisdir/$file"

endif

end

echo "$prefix"

  1. Study the script and be sure to understand it. explain what it does.
  2. Execute the script and correct any error it may have to run it. You will have to change permissions to the shell script file to make it executable (remember the chmod command).
  3. You are required to modify the script, make a copy with the name dirtree_explorer.sh and implement the following changes:
    1. Create a main menu, so when you execute the script the user will have these options:

The current directory is: /usr/xxx/xxxxxx/

1.Enter a directory name

2.Print the directory tree on terminal

3.Print the directory tree to a file

4.Exit

  1. When the user runs the script, it will show the home directory at the top of the main menu, unless a directory was passed as an argument to the script, in that case it will show that one as a current directory in the menu
  2. When the user selects Enter a directory name, the script will capture that into a variable and then it will show that one as a current directory.
  3. When the user selects Print the directory tree on terminal, the script will print the file system structure under this directory in the form of a tree (as the original script did) and then returns to the main menu.
  4. When the user selects Print the directory tree to a file, the script will ask the user for the name of the file and then will save the file system structure under this directory in the form of a tree (as the original script did) to that file and then returns to the main menu. You may place the file in the directory where the shell script is. Remember that you may send data to a file and appended with redirection operators (> or >>).
  5. If the option 4 is selected, the script terminates.

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

More Books

Students also viewed these Databases questions