lxinitd handbook

syntax

lxinitd, lxmenu, and rosh share the same litesh syntax.

Basic Syntax

litesh scripts contain one command per line with arguments.

Here's an example from an lxc container /etc/init.d/rcS.

#!/bin/rosh

/sbin/mount -a
/sbin/ip addr add 10.0.3.27 dev eth0
/sbin/ip route add default via 10.0.3.1
# start the process
/sbin/xtomp

Blank lines are ignored, lines that start with # are comments.

Each line is executed as a subprocess, except limited builtins.

Commands are executed with execv() so they repect $PATH and require absolute paths or ./.

Shebang

The shebang (#!/bin/rosh) is required, even if started with /bin/rosh script

The shebang does not accept arguments or switches.

Textual content

The following rules apply to the content of scripts

  • max 2048 line length
  • max 10 arguments to a command
  • ascii 7bit only, no tabs, no invisible chars apart from space ' ' and \n
  • no \0 characters
  • no utf-8

Whitespace

\n exclusivly splits commands, use of \r is an error.

Whitespace character (ascii 20) exclusivly splits args. No support for $IFS.

The double quote character " is used to wrap strings with spaces. To print quote or slash use standard C string escaping \\ and \".

Builtins

builtins are commands that can be executed without ./

builtins

The builtins available are dependent on the context.

Environment variables

In shell environments (rosh, lxinitd) environment varaibles expansion is supported. Scripts use ${var} syntax, brackets are requried. Emtpy variables result in the empty string "", variables placed together are concatenated.

e.g.

echo ${USER}
echo $USER              # syntax error
echo ${USER}${USER}     # concatenated
echo "${USER}${USER}"   # concatenated
echo "${USER} ${USER}"  # concatenated
echo ${USER} ${USER}    # not concatenated

Branching

Branching is supported with if, elif, else, fi.

e.g.

if command
    echo ${var2}
elif command
    echo ${var2}
else
    echo ${var3}
fi

The command is forked and exiting zero is considered true. N.B. in order for useful branching it may be useful to copy /usr/bin/test and symlink /usr/bin/[, this is not done by default in lxinitd containers.

The commands "true" and "false" are handled by builtins and do not fork.

if ${debug}
    echo ${var2}
fi

A future version may implement [[, syntax should be considered reserved.



by teknopaul