-
Notifications
You must be signed in to change notification settings - Fork 1
/
shell.sh
executable file
·48 lines (40 loc) · 958 Bytes
/
shell.sh
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
#!/bin/sh
# -*- mode: sh; -*-
# vim: set filetype=sh :
set -u # no uninitialized
set -e # exit on error ( use "|| true" or wrap in "set +e" "set -e" to block )
set -o pipefail # also exit if error in piped command -- must disable for acceptable errors
IFS=$(printf '\n\t') # spaces don't split items
bindir=$(cd $(dirname "$0") && pwd)
usage () {
cat <<_USAGE
This program does ...
_USAGE
}
onexit () {
: # necessary cleanup steps
}
trap onexit EXIT
main() {
# option parsing
while getopts "h" opt; do
case $opt in
h)
usage >&2
exit 0
;;
esac
done
shift $((OPTIND-1))
# iterate through all command-line parameters
if [ -z "$1" ]; then
files='-'
else
files="$*"
fi
for f in $files; do
[ '-' = "$f" ] && f=/dev/stdin # substitute stdin for missing args or -
: # process files here
done
}
main "$@"