Browse Source

Wrap main code into main() to avoid globals

Alois Mahdal 6 years ago
parent
commit
e974d5c7f4
1 changed files with 17 additions and 11 deletions
  1. 17
    11
      bin/dissect_url

+ 17
- 11
bin/dissect_url View File

@@ -9,15 +9,21 @@ dissect() {
9 9
     echo ""
10 10
 }
11 11
 
12
-if [[ -n "$1" ]]; then
13
-    dissect "$1"
14
-else
15
-    i=0
16
-    while read url;
17
-    do
18
-        if [[ -z "$url" ]]; then exit 0; fi
19
-        i=`expr $i + 1`
20
-        printf "=== url %02d =============================================\n" $i
12
+main() {
13
+    local url=$1
14
+    local i=0
15
+    if [[ -n "$url" ]]; then
21 16
         dissect "$url"
22
-    done
23
-fi
17
+    else
18
+        i=0
19
+        while read url;
20
+        do
21
+            if [[ -z "$url" ]]; then exit 0; fi
22
+            i=`expr $i + 1`
23
+            printf "=== url %02d =============================================\n" $i
24
+            dissect "$url"
25
+        done
26
+    fi
27
+}
28
+
29
+main "$@"