-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.sh
executable file
·72 lines (64 loc) · 1.16 KB
/
utils.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
#!/usr/bin/env bash
version() {
echo "Version 0.0.0"
}
# Check input
checkreqvar() {
reqvar=( "$@" )
for var in "${reqvar[@]}"
do
if [[ -z ${!var+x} ]]
then
echo "${var} is unset, exiting program" && exit 1
else
echo "${var} is set to ${!var}"
fi
done
}
checkoptvar() {
optvar=( "$@" )
for var in "${optvar[@]}"
do
echo "${var} is set to ${!var}"
done
}
removeniisfx() {
echo ${1%.nii*}
}
if_missing_do() {
case $1 in
mkdir )
if [ ! -d $2 ]
then
echo "Create folder(s)" "${@:2}"
mkdir -p "${@:2}"
fi
;;
stop )
if [ ! -e $2 ]
then
echo "$2 not found"
exit 1
fi
;;
* )
if [ ! -e $3 ]
then
printf "%s is missing, " "$3"
case $1 in
copy ) echo "copying $2"; cp $2 $3 ;;
move ) echo "moving $2"; mv $2 $3 ;;
mask ) echo "binarising $2"; fslmaths $2 -bin $3 ;;
* ) echo "and you shouldn't see this"; exit ;;
esac
fi
;;
esac
}
replace_and() {
case $1 in
mkdir) if [ -d $2 ]; then echo "$2 exists already, removing first"; rm -rf $2; fi; mkdir -p "${@:2}" ;;
touch) if [ -d $2 ]; then echo "$2 exists already, removing first"; rm -rf $2; fi; touch $2 ;;
* ) echo "This is wrong"; exit ;;
esac
}