-
Notifications
You must be signed in to change notification settings - Fork 2
/
DelFile
executable file
·51 lines (43 loc) · 895 Bytes
/
DelFile
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
#!/usr/bin/env bash
. "${BASH_SOURCE[0]%/*}/function.sh" "" || exit
usage()
{
echot "\
Usage: $(ScriptName) FILES
Safely delete files
-a, --ask ask to delete the file
-t, --test do not delete the file"
exit $1
}
init() { :; }
args()
{
unset ask file test
while [ "$1" != "" ]; do
case "$1" in
-a|--ask) ask="true";;
-h|--help) IsFunction "${command}Usage" && ${command}Usage || usage 0;;
-t|--test) test="true";;
*)
! IsOption "$1" && [[ ! $file ]] && { file="$1"; shift; continue; }
UnknownOption "$1"
esac
shift
done
[[ ! $file ]] && MissingOperand "file"
args=("$@")
}
run()
{
init; args "$@";
delete "$file"
}
delete()
{
[[ ! -f "$file" ]] && return
if [[ $ask ]]; then
ask "Are you sure you want to delete file \"$file\"" -dr n || return 1
fi
[[ $test ]] && echo "DelFile: would have deleted \`$file\`" || rm -f "$file"
}
run "$@"