{{Header}} {{title|title= {{project_name_long}} Coding Style }} {{#seo: |description=Simplicity, Brevity, Sparingly Forking Upstream Projects, Feature Removability }}
if
and similar.
Bad example:
machine_id() { if ! test -f /etc/machine-id ; then existing_machine_id="$(cat /etc/machine-id)" ## ... fi }In above example there is need need to put everything under the
if
. This is specifically important when there are several levels of conditionals.
Example good:
machine_id() { if ! test -f /etc/machine-id ; then return 0 fi existing_machine_id="$(cat /etc/machine-id)" ## .... }= Shell Scripts = == avoid sed awk whenever possible == There might be some older code (before introduction of str_replace) that uses sed / awk. Patches welcome to port to str_replace. == use str_replace whenever possible == [https://github.com/{{project_name_short}}/helper-scripts/blob/master/usr/bin/str_replace str_replace] is installed in {{project_name_short}} by default. ([https://github.com/{{project_name_short}}/helper-scripts/blob/master/man/str_replace.1.ronn man page]) https://github.com/Samer-Al-iraqi/Linux-str_replace/ == use type -P instead of which == Please do not use
which
. Please use type -P
instead.
https://mywiki.wooledge.org/BashFAQ/081
== Proper Whitespace Handling ==
See [[Dev/bash]].
= See Also =
* [[Dev/Source Code Intro|Source Code Introduction]]
[[Category:Design]]
{{Footer}}