-
Notifications
You must be signed in to change notification settings - Fork 0
/
r-file-creation.sh
executable file
·73 lines (64 loc) · 1.43 KB
/
r-file-creation.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
#!/bin/bash
function get_last() {
max=0
for dir in $basepath/*; do
num=$(echo $dir | tr -dc '0-9')
if (( num > max )); then
max=$num
fi
done
echo $max
}
function format_path() {
lastchar=$(echo "${basepath:(-1)}")
if [[ $lastchar == "/" ]]; then
basepath=${basepath::-1}
fi
}
append=false;
opterr=0
while getopts p:i:n:ha flag
do
case "$flag" in
p) basepath=${OPTARG};;
i) iteration=${OPTARG};;
h) cat << EOF
Usage: create-template.sh [OPTION]...
-p : Pathname for directory creation
-i : Iteration count for how many paths want to create.
-a : Append -i count of new file
-n : preffered path name. Default value: problem
EOF
exit
;;
n) name=${OPTARG};;
a) append=true;;
esac
done
if [[ -z $iteration || -z $basepath ]]; then
echo "Iteration and Path must be specified. Use -i and -p options."
exit
fi
if [[ -z $name ]]; then
name="problem"
fi
format_path
begin=1
if [[ $append == true ]]; then
max=$(get_last)
iteration=$((iteration+$max+1))
begin=$((max+1))
echo iteration $iteration
echo begin $begin
else
iteration=$((iteration+1))
echo iteration $iteration
fi
for ((i = begin ; i < $iteration ; i++)); do
fname=$name$i
path=$basepath/$fname
echo "Created path: $path"
mkdir $path
cp .main $path/main.c
cp .rdme $path/README.md
done