-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathglobal.sh
More file actions
executable file
·69 lines (58 loc) · 1.57 KB
/
global.sh
File metadata and controls
executable file
·69 lines (58 loc) · 1.57 KB
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
64
65
66
67
68
69
#!/bin/sh
##########################################################################
# Title : global - execute command in every subdirectory
# Author : Heiner Steven <heiner.steven@odn.de>
# Date : 1994-09-29
# Requires :
# Category : File Utilities
# SCCS-Id. : @(#) global 1.3 03/12/19
##########################################################################
# Description
#
##########################################################################
PN=`basename "$0"` # program name
VER='1.3'
usage () {
echo >&2 "$PN - execute command in subdirectories, $VER (stv '94)
usage: $PN [-v] command [argument ...]
-v verbose, print current path
The given command is executed in every subdirectory of the current
directory, depth first. At last it is executed in the current
directory, too.
If the command contains embedded blanks, it must be enclosed in
quotation marks \"...\" or '...'."
exit 1
}
err () {
for i
do echo "$PN: $i" >&2
done
}
fatal () { err "$@"; exit 1; }
msg () { [ "$silent" = no ] && err "$@"; }
MyPath=$0
# Export "silent" to subshells, because parameters to the
# invoking shells are not passed to the subshells
: ${silent:=yes} # yes/no, may be set from calling shell
export silent
while [ $# -gt 0 ]
do
case "$1" in
-v) silent=no;;
--) shift; break;; # End of parameter list
-h) usage;;
-*) usage;;
*) break;; # Command
esac
shift
done
[ $# -lt 1 ] && usage
for i in *
do
[ -d "$i" ] || continue
cd "$i"
"$MyPath" "$@" # recurse into subdirectories
cd ..
done
msg "`pwd`"
eval "$@"