Style Guide

In order to make LinuxGSM as coherent as possible, we adopted some code conventions to follow. Here are some of them.


Naming variables

Variables should be made of lowercase letters only and should be descriptive enough to understand its purpose (even if the variable is longer that preferred).

Defining variables

Any variable should be defined through double quotes


Calling variables

Variable should always be called between brackets and double quotes to prevent globbing and word splitting.

echo "${var}"


Directories are called using LinuxGSM directories variables, or relative to those. Common directory variables can be found in and _default.cfg .


mkdir -pv "${servercfgdir}"
mkdir -pv "${lgsmdir}/config-default/config-game"
du -sh "${rootdir}" 2> /dev/null
find "${executabledir}/bin"

if Statements

If statements should look like the following

if [ "${shortname}" == "csgo" ];then
   # content

if statements with multiple options like so

if [ "${shortname}" == "csgo" ]||[ "${shortname}" == "css" ]; then
   # content

Conditional checks


  • The if [ statement ]; then should be a one-liner operation.

  • Signs comparators like ==, lt, lt etc. are preferred to -eq, -le, -lt.

  • Anything within an if statement must be tabulated one step deeper.


if [ "${test}" == "${var}" ]; then

Expression Standards

Common if expressions LinuxGSM uses. More expressions here.



if directory exists

! -d

if directory does not exist


if file exists

! -f

if file does not exist


true if length of string is zero


true if length of string is non-zero


true if the variable exists

Do not use ! -z or ! -n

There is a distinct difference between -n and -v.

-n is used to check is a variable is set and not if it exists -v is used to check if a variable exists and not it is set

if [ -n "${var}" ]; then
 # Variable is set
if [ -z "${var}" ]; then
 # Variable is not set
# OR
if [ -v var ]; then
 # Variable exista
# var is missing
if [ ! -v var ]; then
 # Variable does not exist


  • Loops should be a one liner statement.

  • Anything within a loop must be tabulated one step deeper.

while [ "${var}" < "${cap}" ]; do
    echo "This is tabulated"
    let var=var+1


As English is not always the native language of a developer, comments should use a formal writing style and be straight to the point. If unsure this short formal writing guide will help.

# Using comments help developers understand complex code, but should be used sparingly.


  • Function should be named starting with fn_ and using lowercase letters only.

  • Any recurrent task should be put into a function.

  • Anything within a function must be tabulated one step deeper.


    echo "This is tabulated"


  • Messages should be given using forms

  • Additional information messages are given in the form of echo -e " * Message here"

Automated Messages

Automated messages are used with any commands that are non-interactive. Examples of this include Start, Stop and Monitor. There are various different alert messages available see Exit-Codes for details.

Each automated message starts with fn_print_dots to show a process is happening but with no known outcome.


[ .... ] Starting fctrserver:

Once an outcome of a process is known the message uses an outcome message like fn_print_ok or fn_print_fail


[  OK  ] Starting fctrserver: Factorio Server

The option of a newline is also available by appending _nl for example fn_print_ok_nl. This will add a carriage return to the message preventing it being overwritten by the next message.

[  OK  ] Stopping fctrserver: Graceful: CTRL+c: 2: OK
[ .... ] Starting fctrserver: Factorio Server


Interactive messages contain extra detail at the begining of the message that is pre-populated. Full stops must not be used with this type of message.

Interactive Messages

Interactive messages are used with any commands that have interactive elements. Examples of this include Install, console and debug. There are various different alert messages available see [[Exit-Codes]] for details.

Warning! If fctrserver is already running it will be stopped.

standard echo commands are normally used to supplement an alert or if an alert is not required. Bullet points can also be used

Information! Press "CTRL+b" then "d" to exit console.
Warning! Do NOT press CTRL+c to exit.


Treat interactive messages as a standard sentence. All messages must begin with a capital and end with a full stop

Last updated