Need help writing Scripts


New Member
Once again I would appreciate some help writing scripts, I need 2 of them. The first:

Write a script to remove any empty files (i.e., files with size 0) from directory that is specfied by the user on the command line. The name of the script should be cleanUp. This script should take either 0 or 1 command-line-arguments. If 1 argument is provided, then it is the name of the directory to be cleaned. If no argument is provided, then the script should clean the current-working-directory.

Your script must check that the command-line is valid. The script should output an error message if 2 or more arguments are provided, or if the single argument is not a directory.

The second:

Some files, such as video files, can be very large. Some systems have a limit on the size of any file that can be transmitted by email, or by ftp. To get around such a limit, we could take any large file and break it up into smaller pieces.

Write a script, called fragment, that takes exactly two command line arguments. The first argument should be an integer, which will be a line-count. The second argument should a filename.

Your script should NOT alter or destroy the given file, but should create several smaller files by breaking the original file into pieces. Each of the smaller files will contain line-count lines from the original file. For example, if line-count is 3 and the filename is foobar, then your script should create:

a file called foobar1 which contains lines 1-3 from foobar

a file called foobar2 which contains lines 4-6 from foobar

a file called foobar3 which contains lines 7-9 from foobar


Your script must also check that the command-line is valid. The script should output an error message if the number of command-line-arguments is not 2.

Thanks in advance to anyone one that can help.


Staff member
Gold Supporter
This looks like homework/an assignment.

Please do not ask people to write scripts for you from scratch.

YOU need to write the scripts and tell us what you have done and what the outcome is.

We will try to help you with what you have done --- but doing it for you is another thing.

Staff online