Answered You can hire a professional tutor to get the answer.

QUESTION

The first script should take input from the user using the "read" command. For each line of input do the following:

I need help with Shell Scripting HW.

The first script should take input from the user using the "read" command. For each line of input do the following:

  • if it's a name of a directory, write the directory filename to a file called "dirs.txt"
  • if it's a name of a file, write the filename to a file called "files.txt"
  • Create a command line option "-d" which, if given, will allow the user to change the name of the "dirs.txt" file. (checkfolder.sh -d dirs.list)
  • Create a command line option "--files-list" which, if given, will allow the user to change the name of the "files.txt" file (checkfolder.sh --files-list files.list)
--files- files. . /path/to/another/folder ../subdir .. subdir
  • it should then check each of the given directories (if the directory exists) for files and directories and write the respective name to "dirs.list" and "files.list"

Test your program without parameters, with just -d filename, with just --files-list filename, with just a list of directories, and will all (as in the example above)

The second script should read and output the names of directories from the dirs.txt and display the filename and file size (use the stat command) for each file in files.txt

  • you can use positional parameter 1 for the name of the dirs.txt file and parameter 2 for the name of filex.txt file. (if only one parameter is given, then you'll read from a different file for dirs.txt but will assume files.txt).

The third script will run both of these scripts. It will take zero or 1 parameters. It should produce an error message and exit if there are more than 1 parameter given.

The optional parameter will be a directory path. If none is given, use the current directory ".".

Gather a list of directories in the current or given directory, and use those as parameters to the first script.

Create a set of directories with files in them to test this script.. here's what I've done to create a testing area for this lab:

mkdir paramlab paramlabmkdir -p dir1/dir1a/dir1a1 dir1/dir1a/dir1a2 dir2/dir2a/dir2a1 && touch dir1/file1 dir1/file2 dir1/dir1a/file1 dir1/dir1a/file2 dir2/dir2a/dir2a1/file1 > dir1/file1 > dir1/dir1a/file1 > dir2/dir2a/dir2a1/file1

You might run your scripts like this:

script1.sh -d dirslist.out --files-list files.out dir1/dir1a/dir1a2 dir2/dir2a/dir2a1 dir1

script2.sh dirslist.out files.out

script3.sh dir1

script3.sh dir1/dir1a

NOTE: in order for script 3 to work correctly, the lists in dirslist.out and files.out would have to be complete paths to files, rather than JUST the file name.

here's files.out from script1.sh with my setup above:

dir2/dir2a/dir2a1/file1dir1/file1dor1/file2

Here's the dirslist.out from scrit1.sh with my setup above:

dir1/dir1a

I may test your script with different parameters.

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question