|
@@ -302,11 +302,7 @@ in plugin scenarios.)
|
302
|
302
|
When in doubt, use **double underscore**.
|
303
|
303
|
|
304
|
304
|
|
305
|
|
-Common language constructs
|
306
|
|
---------------------------
|
307
|
|
-
|
308
|
|
-
|
309
|
|
-### variables ###
|
|
305
|
+### Capitalization ###
|
310
|
306
|
|
311
|
307
|
There are three types of variables recognized in terms of this style.
|
312
|
308
|
The distinction is based on scope:
|
|
@@ -324,38 +320,47 @@ The distinction is based on scope:
|
324
|
320
|
be defined in header of the function, that is, before actual code.
|
325
|
321
|
It's also recommended to comment variables here.
|
326
|
322
|
|
327
|
|
-For example:
|
|
323
|
+Functions should be named in `snake_case`.
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+### Example ###
|
|
327
|
+
|
|
328
|
+For example, a file named `greet.sh` would be a valid module named `greet`
|
|
329
|
+if it contained following declarations:
|
328
|
330
|
|
329
|
331
|
#
|
330
|
|
- # My global variable
|
|
332
|
+ # Name of this planet
|
331
|
333
|
#
|
332
|
|
- PLANET_NAME=Earth
|
|
334
|
+ GREET__PLANET=${GREET__PLANET:-Earth}
|
333
|
335
|
|
334
|
|
- main() {
|
|
336
|
+ greet() {
|
|
337
|
+ #
|
|
338
|
+ # Greet persom named $1
|
|
339
|
+ #
|
335
|
340
|
local name=$1 # name to greet
|
336
|
341
|
local TimeOfDay # morning, afternoon or night
|
337
|
342
|
TimeOfDay=$(determine_timeofday)
|
338
|
|
- greet "$name"
|
|
343
|
+ __greet__mkgreet "$name"
|
339
|
344
|
}
|
340
|
345
|
|
341
|
|
- greet() {
|
|
346
|
+ __greet__mkgreet() {
|
342
|
347
|
#
|
343
|
348
|
# Greet user $1 based on $TimeOfDay
|
344
|
349
|
#
|
345
|
350
|
local name=$1 # name to greet
|
346
|
351
|
case $TimeOfDay in
|
347
|
|
- morning) echo "Good $PLANET_NAME morning, $name!" ;;
|
348
|
|
- afternoon) echo "Nice $PLANET_NAME afternoon, $name!" ;;
|
349
|
|
- night) echo "Sleep well, $name!" ;;
|
|
352
|
+ morning) echo "Good $GREET__PLANET morning, $name!" ;;
|
|
353
|
+ afternoon) echo "Nice $GREET__PLANET afternoon, $name!" ;;
|
|
354
|
+ night) echo "Sleep well, $name!" ;;
|
350
|
355
|
esac
|
351
|
356
|
}
|
352
|
357
|
|
353
|
|
- main "$1"
|
354
|
|
-
|
355
|
358
|
Notice that while `TimeOfDay` is allowed to slip through and be referenced
|
356
|
|
-in `greet()`, `name` is purely local to `main()`, and then again to
|
357
|
|
-`greet()`. (It's probably not a good idea to mix variables like that,
|
358
|
|
-the example is ugly, but you get the point.)
|
|
359
|
+in `__greet__mkgreet()`, `name` is purely local to `greet()`, and then
|
|
360
|
+`name` happens to be declared again in `__greet__mkgreet()`.
|
|
361
|
+
|
|
362
|
+Common language constructs
|
|
363
|
+--------------------------
|
359
|
364
|
|
360
|
365
|
|
361
|
366
|
### functions ###
|