forked from NMAAHC/nmaahcmm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_test
executable file
·94 lines (77 loc) · 2.07 KB
/
_test
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# _test0
mkdir -p "${HOME}"/foo/xxfoo/
bar="${HOME}"/foo
bar1="${HOME}"/foo/*foo
echo "bar is ${bar} bar1 is ${bar}"
### _test1
mkdir -p "${HOME}"/old_foo && find "${HOME}" -type d -name "*foo" -exec mv -vi {} "${HOME}"/new_foo \;
### _test2
# “a” and “arga” have optional arguments with default values.
# “b” and “argb” have no arguments, acting as sort of a flag.
# “c” and “argc” have required arguments.
# set an initial value for the flag
ARG_B=0
# read the options
TEMP=`getopt -o a::bc: --long arga::,argb,argc: -n 'test.sh' -- "$@"`
eval set -- "${TEMP}"
# extract options and their arguments into variables.
while true ; do
case "${1}" in
-a|--arga)
case "${2}" in
"") ARG_A='some default value' ; shift 2 ;;
*) ARG_A="${2}" ; shift 2 ;;
esac ;;
-b|--argb) ARG_B=1 ; shift ;;
-c|--argc)
case "${2}" in
"") shift 2 ;;
*) ARG_C="${2}" ; shift 2 ;;
esac ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
# do something with the variables -- in this case the lamest possible one :-)
echo "ARG_A = ${ARG_A}"
echo "ARG_B = ${ARG_B}"
echo "ARG_C = ${ARG_C}"
### _test3
folder="/Users/medialab/Desktop/foo"
md5deep="md5deep -bre"
### _test4
while getopts ":o:b" OPT ; do
case "${OPT}" in
o)
echo "-o was triggered"
;;
b)
echo "fuck me! -b was triggered"
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
;;
:)
echo "Option -${OPTARG} requires an argument." >&2
exit 1
;;
esac
done
#while getopts ":a" opt; do
# case $opt in
# a)
# echo "-a was triggered!" >&2
# ;;
# \?)
# echo "Invalid option: -$OPTARG" >&2
# ;;
# esac
#done
### _test5
mkdir -p "${HOME}"/foo/xbar
dpx="${HOME}"/dpx/dpx
mkdir -p "${dpx}"
input="${1}"
find "${input}" -type d -name "*bar" -exec rename "{}" "dpx" \;