Browse Source

Add quoting (based on ShellCheck)

Alois Mahdal 3 years ago
parent
commit
d8d080bbab
1 changed files with 49 additions and 49 deletions
  1. 49
    49
      99bottles.sh

+ 49
- 49
99bottles.sh View File

22
     #
22
     #
23
     local numeral=$1    # number in word form
23
     local numeral=$1    # number in word form
24
     case $numeral in
24
     case $numeral in
25
-        *nine)      echo ${numeral%nine}eight;;
26
-        *eight)     echo ${numeral%eight}seven;;
27
-        *seven)     echo ${numeral%seven}six;;
28
-        *six)       echo ${numeral%six}five;;
29
-        *five)      echo ${numeral%five}four;;
30
-        *four)      echo ${numeral%four}three;;
31
-        *three)     echo ${numeral%three}two;;
32
-        *two)       echo ${numeral%two}one;;
33
-        one)        echo zero;;
34
-        *-one)      echo ${numeral%-one};;
35
-        *one)       echo ${numeral%one};;
36
-        ten)        echo nine;;
37
-        eleven)     echo ten;;
38
-        twelve)     echo eleven;;
39
-        *teen)      teenpred $numeral;;
40
-        *ty)        tenspred $numeral;;
25
+        *nine)      echo "${numeral%nine}eight" ;;
26
+        *eight)     echo "${numeral%eight}seven" ;;
27
+        *seven)     echo "${numeral%seven}six" ;;
28
+        *six)       echo "${numeral%six}five" ;;
29
+        *five)      echo "${numeral%five}four" ;;
30
+        *four)      echo "${numeral%four}three" ;;
31
+        *three)     echo "${numeral%three}two" ;;
32
+        *two)       echo "${numeral%two}one" ;;
33
+        one)        echo "zero" ;;
34
+        *-one)      echo "${numeral%-one}" ;;
35
+        *one)       echo "${numeral%one}" ;;
36
+        ten)        echo "nine" ;;
37
+        eleven)     echo "ten" ;;
38
+        twelve)     echo "eleven" ;;
39
+        *teen)      teenpred "$numeral" ;;
40
+        *ty)        tenspred "$numeral" ;;
41
         zero)       echo "";  #to terminate
41
         zero)       echo "";  #to terminate
42
     esac
42
     esac
43
 }
43
 }
49
     local numeral=$1    # number in word form
49
     local numeral=$1    # number in word form
50
     case $numeral in
50
     case $numeral in
51
         thirteen)   echo twelve;;
51
         thirteen)   echo twelve;;
52
-        *)          echo $(crunchprefix $(pred $(uncrunchprefix ${numeral%teen})))teen;;
52
+        *)          echo "$(crunchprefix "$(pred "$(uncrunchprefix "${numeral%teen}")")")teen" ;;
53
     esac
53
     esac
54
 }
54
 }
55
 
55
 
60
     local numeral=$1    # number in word form
60
     local numeral=$1    # number in word form
61
     case $numeral in
61
     case $numeral in
62
         twenty)     echo nineteen;;
62
         twenty)     echo nineteen;;
63
-        *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${numeral%ty})))ty-nine;;
63
+        *) echo "$(crunchprefix --tens "$(pred "$(uncrunchprefix "${numeral%ty}")")")ty-nine";;
64
     esac
64
     esac
65
 }
65
 }
66
 
66
 
74
     #
74
     #
75
     local numeral       # number in word form
75
     local numeral       # number in word form
76
     local tensop        # 'true' if --tens option is active
76
     local tensop        # 'true' if --tens option is active
77
-    [ $1 = --tens ] && { tensop=true; shift; }
77
+    [ "$1" = --tens ] && { tensop=true; shift; }
78
     numeral=$1
78
     numeral=$1
79
     case $numeral in
79
     case $numeral in
80
-        two)    [ -n "$tensop" ] && echo twen || echo $numeral;;
80
+        two)    [ -n "$tensop" ] && echo twen || echo "$numeral";;
81
         three)  echo thir;;
81
         three)  echo thir;;
82
-        four)   [ -n "$tensop" ] && echo 'for' || echo $numeral;;
82
+        four)   [ -n "$tensop" ] && echo 'for' || echo "$numeral";;
83
         five)   echo fif;;
83
         five)   echo fif;;
84
-        eight)  [ -n "$tensop" ] && echo eigh || echo $numeral;;
85
-        *)      echo $numeral;;
84
+        eight)  [ -n "$tensop" ] && echo eigh || echo "$numeral";;
85
+        *)      echo "$numeral" ;;
86
     esac
86
     esac
87
 }
87
 }
88
 
88
 
97
         'for')  echo four;;
97
         'for')  echo four;;
98
         fif)    echo five;;
98
         fif)    echo five;;
99
         eigh)   echo eight;;
99
         eigh)   echo eight;;
100
-        *)      echo $prefix;;
100
+        *)      echo "$prefix";;
101
     esac
101
     esac
102
 }
102
 }
103
 
103
 
112
         case "$line" in
112
         case "$line" in
113
             *"one of those bottles"*)   line="$(
113
             *"one of those bottles"*)   line="$(
114
                                             [ $oneBottle = true ] \
114
                                             [ $oneBottle = true ] \
115
-                                             && echo ${line/one of those bottles/that lone bottle} \
116
-                                             || echo $line
115
+                                             && echo "${line/one of those bottles/that lone bottle}" \
116
+                                             || echo "$line"
117
                                         )"
117
                                         )"
118
                                         ;;
118
                                         ;;
119
             *"one down"*)               line="$(
119
             *"one down"*)               line="$(
120
                                             [ $oneBottle = true ] \
120
                                             [ $oneBottle = true ] \
121
-                                             && echo ${line/one down/it down} \
122
-                                             || echo $line
121
+                                             && echo "${line/one down/it down}" \
122
+                                             || echo "$line"
123
                                         )"
123
                                         )"
124
                                         ;;
124
                                         ;;
125
             *bottles*)                  oneBottle=false;;
125
             *bottles*)                  oneBottle=false;;
127
         esac
127
         esac
128
         #Some say the twenties should have no hyphen
128
         #Some say the twenties should have no hyphen
129
         line="${line/twenty-/twenty }"
129
         line="${line/twenty-/twenty }"
130
-        echo $line
130
+        echo "$line"
131
     done
131
     done
132
 }
132
 }
133
 
133
 
137
     #
137
     #
138
     local line      # every line
138
     local line      # every line
139
     while read line; do
139
     while read line; do
140
-        echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
141
-        echo ${line#?}
140
+        echo -n "${line:0:1}" | tr '[:lower:]' '[:upper:]'
141
+        echo "${line#?}"
142
     done
142
     done
143
 }
143
 }
144
 
144
 
149
     local line      # every line
149
     local line      # every line
150
     while read line; do
150
     while read line; do
151
         case "${line}" in
151
         case "${line}" in
152
-            [Ii]f*)     echo ${line},;;
152
+            [Ii]f*)     echo "${line},";;
153
             '')         echo;;
153
             '')         echo;;
154
-            *)          echo ${line}.;;
154
+            *)          echo "${line}.";;
155
         esac
155
         esac
156
     done
156
     done
157
 }
157
 }
161
     # Write one verse with number $1
161
     # Write one verse with number $1
162
     #
162
     #
163
     local nb=$1     # numeral
163
     local nb=$1     # numeral
164
-    echo $nb bottles of beer on the wall
165
-    echo $nb bottles of beer
166
-    if [ $nb = zero ]; then
167
-        echo Go to the store and buy some more
164
+    echo "$nb bottles of beer on the wall"
165
+    echo "$nb bottles of beer"
166
+    if [ "$nb" = zero ]; then
167
+        echo "Go to the store and buy some more"
168
         nb=ninety-nine
168
         nb=ninety-nine
169
     else
169
     else
170
-        echo $breakLine
171
-        nb=$(pred $nb)
170
+        echo "$breakLine"
171
+        nb=$(pred "$nb")
172
     fi
172
     fi
173
-    echo $nb bottles of beer on the wall
173
+    echo "$nb bottles of beer on the wall"
174
 }
174
 }
175
 
175
 
176
 poeticize() {
176
 poeticize() {
184
         case "$rest" in
184
         case "$rest" in
185
             *beer*)
185
             *beer*)
186
                 first=${first/zero/no}
186
                 first=${first/zero/no}
187
-                syl=$(syllables ${first% *})
187
+                syl=$(syllables "${first% *}")
188
                 case $syl in  #improve meter
188
                 case $syl in  #improve meter
189
-                    1|2)    echo $first 'more' $rest;;
190
-                    *)      echo $first $rest;;
189
+                    1|2)    echo "$first more $rest";;
190
+                    *)      echo "$first $rest" ;;
191
                 esac
191
                 esac
192
                 ;;
192
                 ;;
193
-            *)  echo $first $rest
193
+            *)  echo "$first $rest"
194
         esac
194
         esac
195
     done
195
     done
196
 }
196
 }
210
     case $word in
210
     case $word in
211
         *seven*)    let $((n = n+1));;
211
         *seven*)    let $((n = n+1));;
212
     esac
212
     esac
213
-    echo $n
213
+    echo "$n"
214
 }
214
 }
215
 
215
 
216
 main() {
216
 main() {
222
     wastefulBreakLine="If one of those bottles should happen to fall"
222
     wastefulBreakLine="If one of those bottles should happen to fall"
223
     breakLine=$(
223
     breakLine=$(
224
         [ "$1" = --careless ] \
224
         [ "$1" = --careless ] \
225
-         && echo $wastefulBreakLine \
226
-         || echo $standardBreakLine
225
+         && echo "$wastefulBreakLine" \
226
+         || echo "$standardBreakLine"
227
     )
227
     )
228
     nb=ninety-nine
228
     nb=ninety-nine
229
     while [ -n "$nb" ]; do
229
     while [ -n "$nb" ]; do
230
-        verse $nb
230
+        verse "$nb"
231
         echo
231
         echo
232
-        nb=$(pred $nb)
232
+        nb=$(pred "$nb")
233
     done | poeticize | grammar | punctuate | capitalize
233
     done | poeticize | grammar | punctuate | capitalize
234
 }
234
 }
235
 
235