Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

6 Examples: 6.1 A Shell Script For Deleting Files

The document describes different control flow commands in shell scripts including case, breaksw, default, goto, and examples of using them. It provides an example shell script that uses case to prompt the user before deleting each file or directory and allows the user to continue, quit, or confirm deletion.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

6 Examples: 6.1 A Shell Script For Deleting Files

The document describes different control flow commands in shell scripts including case, breaksw, default, goto, and examples of using them. It provides an example shell script that uses case to prompt the user before deleting each file or directory and allows the user to continue, quit, or confirm deletion.

Uploaded by

arunabhatla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

case string1: commandlist1 breaksw case string2: commandlist2 breaksw default commandlist endsw

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

continue endsw end

(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 *'.)

You might also like