+1 714-215-3097

(Solved) : Unix Shell Programming Exercise Required Make Copy Following Script File Dirtreecsh Prints Q35603104

UNIX Shell Programming

For this exercise you are required to make a copy of thefollowing script into a file dirtree.csh,that prints a directory tree:

#!/bin/tcsh -f

if($#argv == 0) then

        set thisdir=”.”


        set thisdir=$argv[1]


if($?TREEPREFIX) then



        set prefix=””


echo “$prefix|”

set filelist=`ls -A $thisdir`

foreach file ($filelist)


        if(-d “$thisdir/$file”)then

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

                       setenv TREEPREFIX “${prefix}     “


                       setenv TREEPREFIX “${prefix}|    “


           echo $0 “$thisdir/$file”



echo “$prefix”

  1. Study the script and be sure to understand it. Review theslides about Shell Overview and Shell Programming with thedescription of what it does. Incorporate comments indifferent parts of the script to explain what itdoes.
  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 tomake it executable (remember the chmod command).
  3. You are required to modify the script, make a copy with thename and implementthe following changes:
    1. Create a main menu, so when you execute the script the userwill have these options:

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

1.Enter a directory name

2.Print the directory tree onterminal

3.Print the directory tree to afile


  1. When the user runs the script, it will show the home directoryat the top of the main menu, unless a directory was passed as anargument to the script, in that case it will show that one as acurrent directory in the menu
  2. When the user selects Enter a directory name, thescript will capture that into a variable and then it will show thatone as a current directory.
  3. When the user selects Print the directory tree onterminal, the script will print the file system structureunder this directory in the form of a tree (as the original scriptdid) and then returns to the main menu.
  4. When the user selects Print the directory tree to afile, the script will ask the user for the name of the fileand then will save the file system structure under this directoryin the form of a tree (as the original script did) to that file andthen returns to the main menu. You may place the file in thedirectory where the shell script is. Remember that you may senddata to a file and appended with redirection operators (> or>>).
  5. If the option 4 is selected, the script terminates.

Leave a Reply

Your email address will not be published. Required fields are marked *