-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlab10
executable file
·63 lines (49 loc) · 1.39 KB
/
lab10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/tcsh
# Author: Wolfgang C. Strack
# CIS18C Lab 10 script
############### initialize some global variables
set usageMessage = "Usage: $0 directoryName"
############### main
if ( $#argv != 1 ) then
echo $usageMessage
exit 1
endif
########## checkIfValidDir "function"
if ( ! -d "$1" ) then
echo "Error: $1 is not a directory"
exit 1
endif
# cd to directory argument
cd $1
pwd -P | egrep "/home/(student|staff)/$USER" > /dev/null
if ( $status != 0 ) then
echo "Error: `pwd -P` is not your home directory or any of its subdirectories"
exit 1
endif
########## end checkIfValidDir
########## getListOfMatchingFiles "function"
set listOfMatchingFiles = ()
foreach file (`ls`)
if ( -f $file ) head -1 $file | egrep '\#\!/bin/bash' > /dev/null
if ( $status == 0 ) then
set listOfMatchingFiles = ($listOfMatchingFiles $file)
endif
end
########## end getListOfMatchingFiles
if ( $#listOfMatchingFiles == 0 ) then
echo "No files in $(pwd -P) are bash scripts"
exit
endif
########## printMatchingFiles "function"
onintr - # disable ctrl-c signal
echo "Total number of files in `pwd -P` : `ls | wc -l`"
echo "Total number of files in `pwd -P` that are bash scripts: $#listOfMatchingFiles"
echo "Now printing names of files that are bash scripts:"
echo
foreach filename ($listOfMatchingFiles)
echo $filename
sleep 3
end
onintr # reset default handling
########## end printMatchingFiles
cd - > /dev/null