1. The problem statement, all variables and given/known data: A set of Linux shell scripts is required to allow users to ‘remove’ files without them really disappearing until the ‘dustbin’ is emptied. The three shell scripts required are :- del <filename> - This script should move the file called <filename> (a full or relative pathname) to the dustbin directory. trash [-a] - This script should remove the contents of the dustbin directory. If the -a option is not used, the script should print the filenames in the dustbin one by one and ask the user for confirmation that they should be deleted. Otherwise, If the -a option is used, the script should simply remove ALL files from the dustbin. restore [-n] <filename> - This script should move the file called <filename> (a full or relative pathname) back to its original directory. If the -n option is used, the script should allow the file to be moved to a directory nominated by the user. 2. Relevant commands, code, scripts, algorithms: bash code
3. The attempts at a solution (include all code and scripts): del script
Code: #!/bin/bash
Code: #!/bin/bash if ["$1" == "-a"]
Code: #!/bin/bash
*********************************** Is there anything I can do to improve the scripts? Suggestion: Restore function should test to ensure file they are trying to restore is actually in the dustbin. Check for upper or lower case responses in your case statements
(could also consider looping with a trap for non YorN answers):
Code:
Couple of simplification tips: To truncate a file you can use:
Code: > store Instead of piping ls to a tempfile and reading it back, try: (also consider a renamed of variable to "file" to make
things more self-documenting):
Code: for file in *
Have a Linux Problem
Linux Books
Linux Home: Linux System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|