For this assignment, create a set of aliases and functions that perform the tasks described below.
The easiest way to create and edit these is to put them in a text file. You can then source this file to declare or redefine the aliases and functions in the current login shell. If you named the file assn04, you can initialize them with the command sequence :
. assn04
The source command will read each line of the file and enter it into the command line buffer as if you were typing it in yourself.
The aliases and functions will now be loaded into your current login shell. Test your aliases and functions. If you find mistakes, simply edit your "assn04" file, fix your mistakes, save, and source the file again.
To prepare for this assignment, do the following.
Read the man pages on the following entries :
Give the problem number, a general description ( you don't have to copy the problem verbatim ) and any comments to help yourself.
To figure out what comments to use, pretend that you were going to be a TA next year for this course and that you were going to use your assignment as a key to counsel any students asking for help. How would you describe your answers so you could understand it after a year.
When creating a function, if possible use the environmental and local variables instead of specific values to make the functions portable.
For example, if you need to access your home directory, use the variable $HOME instead of /home/hopper/your_z9. This will allow your ta to test your functions in her/his account.
Be careful to notice whether the function or alias has caps in its name.
Write the following simple aliases.
2.(2) Write a alias called fchk that uses test to confirm that the filename specified references a regular file.
3.(2) Write a alias called schk that uses test to confirm that the filename specified is symbolic file.
4.(2) Write a alias called dchk that uses test to confirm that the filename specified is directory file.
5.(2) Write a alias called cchk that uses test to confirm that the filename specified is character special file.
6.(2) Write a alias called bchk that uses test to confirm that the filename specified is block special file.
7.(2) Write a alias called rchk that uses test to confirm that the filename specified references a readable file.
8.(2) Write a alias called echk that uses test to confirm that the file exists. Note : symbolic filename linked to nothing will return false. That is OK.
9.(4) Write an aliasa that prompts the user for a starting directory, then prompts the user for the file to find.
Once it has both, run find starting in the specified directory looking for the file given. Redirect any errors to /dev/null.
Use echo -n to surpress line feed after prompting. And the bash read command to get input.
1. (8 points) Write a function called findit that uses find to search from the directory specified as the 1st argument on the command line and looks for the file specified as the 2nd argument on the command line. Redirect redirect any errors to /dev/null.
Before findit runs find, have it check that the 1st argument exists on the command line.
Use either test's string check for non-zero length. Or you can check that $# variable is greater than zero. $# is the number of arguments passed to a command or function.
If no argument, print an error message.
If 1st argument exists, then check that it represents a directory. If not, print an error message.
Otherwise, run the find.
Pseudo code. if 1st exists on command line ($1) then if 1st argument is an actual directory name then run find to look for file named in 2nd command line argument starting in directory specified in 1st argument. else print error about not a directory endif else print error about missing an argument endif.2. (7 points) Write a function called What that determines the type of file that a filename points to and if the filename itself is a symbolic link and prints the appropriate messages about what it found. Use the aliases created above to test file type.
So What should recognize regular, directory, character special, or block special.
If filetype is not one of those, What should check to see if it does exist anyway and report that. If the file does not exist, report that.
It should also recognize if the filename is a symbolic link that is not linked to an actual file. Most of the test commands will follow a symbolic link to the actual file named before testing its existence and type.
Pseudo code guideline :
if filename is symbolic link print message about symbolic link endif if file is a directory print message about directory else if file is character special file print message about character special else if file is block special file print message about block special else if file is regular file print message about regular special else if file exists print message that file exists but is unrecognized. else print message that there is no file. end ifYou should be able use the aliases defined in 1st part.
The above logic order is a suggestion. Keep in mind that the order of the tests can simplify the logic.
To test What:
Create a directory called junk under your home directory. Make it fully accessible (rwx) only to you the user. Pseudo code guide
Make a backup copy of the assn04 file and email the file to me (berezin) on hopper/turing.