Advertisement
devinteske

Belle Notes

Feb 3rd, 2016
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. belle is a fork of the POSIX compliant sh(1) on FreeBSD.
  2.  
  3. It adds the following functions (potential list):
  4. count
  5. count_ifs
  6. die
  7. dprintf # maybe
  8. err
  9. eval_catch # maybe name change
  10. eval_cmb
  11. expand_number
  12. float
  13. float_add
  14. float_divide
  15. float_multiply
  16. float_subtract
  17. getvar
  18. have
  19. humanize_number
  20. include
  21. include_lang # maybe integrate into include
  22. interrupt # maybe
  23. isint
  24. isset
  25. quietly
  26. replaceall
  27. shell_escape
  28. shell_unescape
  29. snprintf
  30. sprintf
  31. str2var
  32. struct
  33. struct_copy
  34. struct_define
  35. struct_free
  36. struct_new
  37. substr
  38. vsnprintf
  39. vsprintf
  40. which
  41.  
  42. XXX need array subroutines
  43.  
  44. Using these new built-ins provides improved performance for scripts.
  45. You can port your belle script to any of:
  46. + FreeBSD /bin/sh -- POSIX Shell
  47. + Debian or Ubuntu /bin/sh -- Debian Almquist Shell (dash)
  48. + Other Linux -- Bourne Again Shell (bash)
  49. by adding a single line after the invocation, like so:
  50. #!/bin/sh
  51. [ "$BELLE_VERSION" ] || . /etc/belle.subr || exit
  52.  
  53. While the belle interpreter is programmed in C, belle.subr acts as a backward
  54. compatibility layer that can be imported into older shells such as ksh, dash,
  55. or bash, providing all the added functionality of belle.
  56.  
  57. The belle.subr shim for older shells strives to implement the belle feature-set
  58. without forking to externally tracked binaries to maintain performance gains
  59. using benchmarked recipes.
  60.  
  61. The performance of running via the belle interpreter will be greater than that
  62. of running in a compatible shell with belle.subr, which itself will provide
  63. better performance than said compatible shell without belle.subr.
  64.  
  65. An excellent use-case for belle is systems administration and/or prototyping.
  66. It is also uniquely supported for multi-platform work where scripts have to
  67. run under many flavors of UNIX/Linux while maintaining minimal dependencies
  68. (a unique advantage when deploying for BusyBox environments).
  69.  
  70. For an example of how belle can simplify your coding, make it more readable,
  71. and all while running faster, check out the following guide from Ubuntu.com:
  72.  
  73. https://wiki.ubuntu.com/DashAsBinSh
  74.  
  75. According to that page, Ubuntu (at version 15.10 at the time of this writing)
  76. has used dash (the Debian Almquist Shell) as /bin/sh since version 6.10. So the
  77. previous 9 major releases of Ubuntu have all used dash as /bin/sh (previously
  78. it had, like many Linux flavors, been GNU bash).
  79.  
  80. The article from Ubuntu.com gives advice on how to deal with the critical
  81. change at the core of this Distro, including how to handle problems.
  82.  
  83. If you're using belle, you don't have these problems as will be illustrated,
  84. whilst keeping to the adage that developers "use POSIX features" only.
  85.  
  86. NB: The belle additions are built upon POSIX standards.
  87.  
  88. The guide recommends using "eval" instead of ${!...}
  89. belle users can transparently rely on `getvar $var_to_get [$var_to_set]'
  90.  
  91. The guide recommends using "grep" and/or "awk" to replace ${param/?/pat[/str}
  92. belle users can transparently rely on `replaceall' (true?) or replaceone (?)
  93.  
  94. The guide recommends using awk to split a string separated by :
  95. belle users can transparently rely on `replaceall'
  96.  
  97. replaceall "$PATH" : " " LIST
  98. for WORD in $LIST; do
  99. printf "$WORD\n"
  100. done
  101.  
  102. # Though a more efficient approach would be
  103. _IFS="$IFS"
  104. IFS=":"
  105. for WORD in $PATH; do
  106. printf "$WORD\n"
  107. done
  108. IFS="$_IFS"
  109.  
  110. The guide recommends using awk to do a substring instead of ${foo:3[:1]}
  111. belle users can transparently rely on `substr'
  112.  
  113. string_after="some string"
  114. substr -v string "$string_after" 1 3
  115.  
  116. The guide recommends no solution for printf(1) `%q' and `%b'
  117. belle users can transparently rely on `escape' and `unescape'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement