[NBLUG/talk] Homework questions

Ian Sutherland iansuth at sbcglobal.net
Fri Apr 9 12:01:34 PDT 2004


Can you help with the homework questions?

QUESTION 5: Write the contents of  your shell script "mailfile" to mail
your "chexec" script file to yourself with an appropriate subject line.

I came up with:

#!/bin/bash
mail -s "chexec-file" iansuth at sbcglobal.net < chexec

This worked.

F. Now rewrite your "mailfile" script so that it will mail any file to
yourself, with a variable Subject line.  You'll need only one command
line argument:  the file name.  However, you'll use it in more than one
place in the script.

For this one I used $* for the "mail any file" but did not know how to
make a "variable subject line"

QUESTION 6: Write the contents of  your final "mailfile" shell script to
e-mail any file to your outside address, with a subject line containing
"mailfile:", a space, and the name of the file:

I can probably do 6 if I get help with the previous one.

This one has me stumped.

G. The find command uses options and command line arguments in a way not
at all typical of conventional Unix commands. Most Unix commands have as
their first argument the "subject" of the command. For example, the grep
command has the pattern to be searched for (the "subject") as the first
argument and the files to look in ("where to look") as the second
argument. Your task will be to write a shell script that executes a
simplified version of the find command, assuming only 1 or 2 arguments.

If you do not give find a directory to look in, but just use the "name"
option to give it the name of what you want it to look for, the find
command will use the current directory as the default directory, and
will look recursively through all subdirectories for the name you
specified after the "name" option.

H. Write a shell script named "findfile" that takes two arguments:
(a) the first argument will be the file or directory name to look for
(the "subject") 
(b) the second argument will be the directory to search ("where to
look"). (Notice that this is the OPPOSITE order used by the find
command!), and
(c) the shell script will not display any error messages.

Be very careful if you want to use the '*' wildcard in the arguments.
You will need to use double quotes around the subject file or directory
name argument but not around the directory argument, both in the shell
script and on the command line. See page 348 for an illustration of the
difference between the single and double quotes.

QUESTION 7: Write the contents of  your shell script "findfile" to
change the find command into a single command which does all of the
following::
(a) takes the subject file or directory name pattern as its first
argument,
(b) takes the directory to search in as its second argument, and
(c) displays no error messages


Thanks, Ian





More information about the talk mailing list