9 Commits

Author SHA1 Message Date
  Alois Mahdal 2b96e2d4da Add grep to fix missing newline 5 years ago
  Alois Mahdal 73f7b9178a Simplify control flow ("return is the best if") 5 years ago
  Alois Mahdal d97f34d4a2 Remove double initialization 5 years ago
  Alois Mahdal 713db80162 Don't stop on first empty line 5 years ago
  Alois Mahdal a5ada53506 Pass $Url to dissect(), in line with Shellfu coding style 5 years ago
  Alois Mahdal 70486bd21e Use cleaner integer bump syntax 5 years ago
  Alois Mahdal f4c9cb7593 Prefer single-quotes where \n is used 5 years ago
  Alois Mahdal ae5cb3c414 Don't interpret escape sequences in Bash `read` 5 years ago
  Alois Mahdal e974d5c7f4 Wrap main code into main() to avoid globals 5 years ago
1 changed files with 20 additions and 13 deletions
  1. 20
    13
      bin/dissect_url

+ 20
- 13
bin/dissect_url View File

@@ -1,7 +1,10 @@
1 1
 #!/bin/bash
2 2
 
3 3
 dissect() {
4
-    echo $* | perl -pe '
4
+    #
5
+    # Print "dissected" version of $Url
6
+    #
7
+    echo "$Url" | perl -pe '
5 8
         s|(\w)(/[^/])|$1\n    $2|;
6 9
         s|\?|\n    ?\n        |;
7 10
         s|#|\n    #\n        |;
@@ -9,15 +12,19 @@ dissect() {
9 12
     echo ""
10 13
 }
11 14
 
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
21
-        dissect "$url"
22
-    done
23
-fi
15
+main() {
16
+    local Url=$1
17
+    local i=0
18
+    test -n "$Url" \
19
+     && dissect \
20
+     && return 0
21
+    grep . \
22
+      | while read -r Url;
23
+        do
24
+            ((i++))
25
+            printf '=== url %02d =============================================\n' $i
26
+            dissect
27
+        done
28
+}
29
+
30
+main "$@"