Browse code

script.sh - v4.2 - Error func improved and template updated

Fred authored on11/03/2015 22:56:50
Showing1 changed files
... ...
@@ -1,8 +1,8 @@
1 1
 #!/bin/bash
2 2
 # Title:
3 3
 # Version: 
4
-# Author: Frédéric CHEVALIER <fcheval@txbiomedgenetics.org>
5
-# Created in: 2014-1
4
+# Author: Frédéric CHEVALIER <fcheval@txbiomed.org>
5
+# Created in: 2015-
6 6
 # Modified in:
7 7
 # Licence : GPL v3
8 8
 
... ...
@@ -12,7 +12,7 @@
12 12
 # Aims #
13 13
 #======#
14 14
 
15
-# 
15
+aim=""
16 16
 
17 17
 
18 18
 
... ...
@@ -20,7 +20,7 @@
20 20
 # Versions #
21 21
 #==========#
22 22
 
23
-# v0.0 - 2014-1: creation
23
+# v0.0 - 2015-xx-xx: creation
24 24
 
25 25
 
26 26
 
... ...
@@ -28,21 +28,13 @@
28 28
 # Functions #
29 29
 #===========#
30 30
 
31
-# Dependency test
32
-function test_dep {
33
-    which $1 &> /dev/null
34
-    if [[ $? != 0 ]]
35
-    then
36
-        error "Package $1 is needed. Exiting..." 1
37
-    fi
38
-}
39
-
40
-
41 31
 # Usage message
42 32
 function usage {
43 33
     echo -e "
44 34
     \e[32m ${0##*/} \e[00m -i|--in file -o|--out value -v|--val value -s|--switch -h|--help
45 35
 
36
+Aim: $aim
37
+
46 38
 Options:
47 39
     -i, --in        input file
48 40
     -o, --out       name of output file
... ...
@@ -76,32 +68,47 @@ function warning {
76 68
 
77 69
 
78 70
 # Error message
71
+## usage: error "message" exit_code
72
+## exit code optional (no exit allowing downstream steps)
79 73
 function error {
80 74
     if [[ -t 1 ]]
81 75
     then
82 76
         echo -e "\e[31mError:\e[00m $1"
83
-        exit $2
84 77
     else
85 78
         echo -e "Error: $1"
79
+    fi
80
+
81
+    if [[ -n $2 ]]
82
+    then
86 83
         exit $2
87 84
     fi
88 85
 }
89 86
 
90 87
 
88
+# Dependency test
89
+function test_dep {
90
+    which $1 &> /dev/null
91
+    if [[ $? != 0 ]]
92
+    then
93
+        error "Package $1 is needed. Exiting..." 1
94
+    fi
95
+}
96
+
97
+
91 98
 
92 99
 #==============#
93 100
 # Dependencies #
94 101
 #==============#
95 102
 
96
-# 
103
+test_dep
97 104
 
98 105
 
99 106
 
100
-#==========================#
101
-# Declaration of variables #
102
-#==========================#
107
+#===========#
108
+# Variables #
109
+#===========#
103 110
 
104
-# Load variables
111
+# Options
105 112
 while [[ $# -gt 0 ]]
106 113
 do
107 114
     case $1 in
... ...
@@ -137,4 +144,9 @@ fi
137 144
 # Processing #
138 145
 #============#
139 146
 
147
+#-------------#
148
+# Sub-section #
149
+#-------------#
150
+
151
+
140 152
 exit 0