This assignment will give you more practice in writing shell scripts.

The Task

You are to write scripts that give a more physical feeling to the UNIX commands you use. In this physical model to copy or move files from one directory to another directory, you cd to the first directory and then "pick up" the files and then go to the second directory and "drop" them.

DANGER DANGER. The commands you are creating create and destroy files and directories. If miscoded or the tests misused they can destroy files in your system. Build and test with caution.

You may assume there is a temp directory called Tmp in your home directory ($HOME/Tmp) that you can create directories and files in. IMPORTANT: You will want to create and possibly destroy a directory in the temp directory in which these commands will save stuff. You might also find it useful to remember the -p option on mkdir. You can assume that the shell variable HOME is defined. You probably want to use the shell variable $#. Do not print out anything that isn't asked for.

Here are the commands you should implement to get this effect:

  • save ( 30 pts):
    save {list of files and/or directories}
    

    This command works on files and directories. It saves the specified files in a save directory to be recalled by commands to follow. If no files are specified then it writes the input from stdin into a file named "saveData" in the same temporary location. Another way to view this is when input comes from stdin, there is no name for the file so save as if it was in a file called "saveData".

    If there are any files that were saved before this command was given, they are quietly removed from the temporary directory and discarded. The output of the save command is a list of all of the saved files and/or directories in the the save directory including those that begin with a dot. Directories should not be recursively displayed. The same output occurs for the remaining commands that require a list of files in the save directory. This includes dot files. Example:

    save cats dogs  # makes copy of files cats and dogs removes previous saves
    ps -ef | save   # makes copy of stdin data in a file called saveData
    

  • drop ( 20 pts):
    drop
    
    This command takes all the files that are saved and copies them into the current directory. It does not delete them from the saved directory. That is you can repeatedly drop files around your system if you choose. The output of this command is a list of all of the files in the save directory. This includes dot files.

  • grab ( 20 pts):
    grab {list of files and/or directories}
    
    This commands does the same as save except it removes the files from the current directory when it copies them. Essentially this does a save followed by a remove. Or you could think of it as doing a move. If no files or directories are listed it does what save does in this case. The output of this command is a list of all of the files in the save directory. This includes dot files.

  • add ( 20 pts):
    add {list of files and/or directories}
    
    This commands does the same as save except it doesn't remove any previously saved files and instead it adds them to the saved area. If a file already exists and its permissions allow it, it will write over it. Note that if you cd to directory X and save fred and then cd to directory Y and then add fred it will overwrite the first saved fred! Again, if no filename is supplied it will save the stdin to file saveFile in the save directory overwriting any previous version, if it exists. The output of this command is a list of all of the files in the save directory. This includes dot files.

  • get ( 10 pts):
    get
    
    This command concatenates the contents of all the save files and sends it to stdout. This is extremely useful in that it allows you to squirrel-away output and call it back shortly thereafter. This command should concatenate the non-dotted (visible) files in the save directory. For this assignment assume the files are all regular text files. The get command is used to save the output of something temporarily and then get them from inside an editor or as input to pipe.

  • lssave ( 10 pts):
    lssave
    
    This command will simply list all the files and directories in the save directory as was done in the above commands. If you want to call this command from the other commands that works well.

Testing

To test your code and better understand the definition of the functions there is a tar in the sidebar that contains a mock directory structure. Included is also a test script and the expected output when the test script is run in the same directory where the tar is exploded.

Submission

Homework will be submitted as an uncompressed tar file to the assignment in BBLearn when the assignment is ready there. See class news.

Have fun.