Extended shell linker
Find a file
2021-01-20 16:59:27 +01:00
include implement [[ ]] debashify 2021-01-20 16:31:31 +01:00
src replace [[ debashify 'echo|grep' into 'expr' 2021-01-20 16:59:27 +01:00
.gitignore Ignore generated version header 2020-11-14 17:33:38 +01:00
generate_version.sh Add version tag for debug build 2020-11-14 18:24:47 +01:00
LICENSE Initial commit 2020-08-28 10:46:02 +02:00
Makefile fix issue on <() parsing + add debug NO_PARSE_CATCH 2021-01-08 11:07:20 +01:00
README.md update doc 2021-01-20 11:50:24 +01:00

lxsh

Extended shell linker for linking, processing and minimizing shell code

Installing

linux-amd64

Download the lxsh-linux-amd64.tar.gz archive, extract it, and move the lxsh binary in a PATH folder (/usr/local/bin is the recommended).

Other

See Build.

Features

Command extensions

lxsh implements special linking commands that are resolved at linking. These commands can be placed anywhere within the script like regular commands.

  • %include : allows to insert file contents
  • %resolve : allows to execute a shell command and insert its output

See lxsh --help-commands for more details

Minimize code

Reduce code size to a minimum without changing functionality with the -m option.

Further minimizing

The script can be further minimized by altering code elements. This can cause some change in execution behavior if you are not careful.

Variable names can be minimized with --minimize-var, use --exclude-var to exclude variables from being minimized (for example environment config).

Function names can be minimized with --minimize-fct, use --exclude-fct to exclude functions from being minimized.

Unused functions and variables can be removed with --remove-unused.

Debashify

Bash specific features can be translated into POSIX code.

This is a work in progress and for now only some are translated:

  • <() and >() process substitutions
  • <<< herestring
  • >&, &> and &>> output redirects

Other features

Output generated code

By default lxsh outputs generated shell code to stdout. You can use the -o option to output to a file and make this file directly executable.

The resulting script is not dependent on lxsh

Live execution

Directly execute an extended lxsh script with either

  • -e option
  • shebang is lxsh

Direct execution introduces direct dependency on lxsh and code generation overhead, therefore it should be avoided outside of development use

There may be some issues with direct execution as of now

Variable/Function/command listing

You can list all calls of variables, functions or commands with --list-* options

Build

Dependencies

Depends on ztd

Building

Use make -j11 to build.
You can use environment variables to alter some aspects:

  • DEBUG: when set to true will generate a debug binary with profiling
  • RELEASE: when set to true, the version string will be generated for release format
  • STATIC: when set to true will statically link libraries

Work in progress

The full POSIX syntax is supported and should produce a functioning result.
However not all bash syntax is supported yet.

Known bash issues

  • ${!VAR} does not register as a variable
  • Extended globs (*()) are not supported
  • (()) creates two subshells instead of one object
  • Unsetting functions will not work properly when minimizing variables or functions