Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- belle is a fork of the POSIX compliant sh(1) on FreeBSD.
- It adds the following functions (potential list):
- count
- count_ifs
- die
- dprintf # maybe
- err
- eval_catch # maybe name change
- eval_cmb
- expand_number
- float
- float_add
- float_divide
- float_multiply
- float_subtract
- getvar
- have
- humanize_number
- include
- include_lang # maybe integrate into include
- interrupt # maybe
- isint
- isset
- quietly
- replaceall
- shell_escape
- shell_unescape
- snprintf
- sprintf
- str2var
- struct
- struct_copy
- struct_define
- struct_free
- struct_new
- substr
- vsnprintf
- vsprintf
- which
- XXX need array subroutines
- Using these new built-ins provides improved performance for scripts.
- You can port your belle script to any of:
- + FreeBSD /bin/sh -- POSIX Shell
- + Debian or Ubuntu /bin/sh -- Debian Almquist Shell (dash)
- + Other Linux -- Bourne Again Shell (bash)
- by adding a single line after the invocation, like so:
- #!/bin/sh
- [ "$BELLE_VERSION" ] || . /etc/belle.subr || exit
- While the belle interpreter is programmed in C, belle.subr acts as a backward
- compatibility layer that can be imported into older shells such as ksh, dash,
- or bash, providing all the added functionality of belle.
- The belle.subr shim for older shells strives to implement the belle feature-set
- without forking to externally tracked binaries to maintain performance gains
- using benchmarked recipes.
- The performance of running via the belle interpreter will be greater than that
- of running in a compatible shell with belle.subr, which itself will provide
- better performance than said compatible shell without belle.subr.
- An excellent use-case for belle is systems administration and/or prototyping.
- It is also uniquely supported for multi-platform work where scripts have to
- run under many flavors of UNIX/Linux while maintaining minimal dependencies
- (a unique advantage when deploying for BusyBox environments).
- For an example of how belle can simplify your coding, make it more readable,
- and all while running faster, check out the following guide from Ubuntu.com:
- https://wiki.ubuntu.com/DashAsBinSh
- According to that page, Ubuntu (at version 15.10 at the time of this writing)
- has used dash (the Debian Almquist Shell) as /bin/sh since version 6.10. So the
- previous 9 major releases of Ubuntu have all used dash as /bin/sh (previously
- it had, like many Linux flavors, been GNU bash).
- The article from Ubuntu.com gives advice on how to deal with the critical
- change at the core of this Distro, including how to handle problems.
- If you're using belle, you don't have these problems as will be illustrated,
- whilst keeping to the adage that developers "use POSIX features" only.
- NB: The belle additions are built upon POSIX standards.
- The guide recommends using "eval" instead of ${!...}
- belle users can transparently rely on `getvar $var_to_get [$var_to_set]'
- The guide recommends using "grep" and/or "awk" to replace ${param/?/pat[/str}
- belle users can transparently rely on `replaceall' (true?) or replaceone (?)
- The guide recommends using awk to split a string separated by :
- belle users can transparently rely on `replaceall'
- replaceall "$PATH" : " " LIST
- for WORD in $LIST; do
- printf "$WORD\n"
- done
- # Though a more efficient approach would be
- _IFS="$IFS"
- IFS=":"
- for WORD in $PATH; do
- printf "$WORD\n"
- done
- IFS="$_IFS"
- The guide recommends using awk to do a substring instead of ${foo:3[:1]}
- belle users can transparently rely on `substr'
- string_after="some string"
- substr -v string "$string_after" 1 3
- The guide recommends no solution for printf(1) `%q' and `%b'
- belle users can transparently rely on `escape' and `unescape'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement