-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
76 lines (58 loc) · 1.14 KB
/
test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
cd `dirname $0`
. ./common.sh
usage="
Script that simply creates a empty file.
Usage:
$(basename $0) --file <filename>
where
--touch <filename> - Name of the file to create
--debug - Flag that sets debugging mode.
--log - Path to the log file that will log all meaningful commands
Example:
$(basename $0) --touch test.flag --debug
"
dir_resolve()
{
cd "$1" 2>/dev/null || return $? # cd to desired directory; if fail, quell any error messages but return exit status
echo "`pwd -P`" # output full, link-resolved path
}
mypath=${0%/*}
mypath=`dir_resolve $mypath`
cd $mypath
debug=0
while [[ $# > 0 ]]
do
key="$1"
shift
case $key in
--debug)
debug=1
;;
--log)
log=$1
shift
;;
--touch)
filename="$1"
shift
;;
-*)
echo "Error: Unknown option: $1" >&2
echo "$usage" >&2
;;
esac
done
if [ -n "$debug" ]; then
if [ -z "$log" ]; then
log=/dev/stdout
fi
fi
if [ -z "$filename" ]; then
errcho "You must specify file name with parameter --touch"
echo "$usage" >&2
exit 1
fi
if [ ! -f "${filename}" ]; then
logexec touch "${filename}"
fi