6 Examples: 6.1 A Shell Script For Deleting Files
6 Examples: 6.1 A Shell Script For Deleting Files
The given string str is successively matched against the case patterns. Control flow is switched to where the first match occurs. As in file name expansion, a case label may be a literal string, or contain variable substitution, or contain wild-card character such as *,?, etc. 5. Goto The goto command provides a way to branch unconditionally to a line identified by a label.
goto lab
where lab is a label on a line (by itself) somewhere in the script in the form
lab:
6 Examples
6.1 A Shell Script For Deleting Files
This code, which we will call Del, will delete files like rm does, prompting for your confirmation for each file to be deleted, including directory files (which the -i option of rm won't do).
#! /bin/csh -f foreach name ($argv) if ( -f $name ) then echo -n "delete the file '${name}' (y/n/q)?" else echo -n "delete the entire directory '${name}' (y/n/q)? " endif set ans = $< switch ($ans) case n: continue case q: exit case y: rm -r $name
(Before reading further, try this program yourself. Set up a test directory, with several files in it, at least one of which is a subdirectory, with at least one file there. Then type `Del *'.)