Supported Commands

Complete command reference for MXCMD built-ins, file tools, list operations, debug helpers, and regex processing.

All file paths should be wrapped in quotes, especially when paths contain spaces.

This page is organized as a practical reference: each command includes a short purpose statement, syntax, and example where useful. Numeric return conventions generally follow shell behavior: 0 indicates success/true, non-zero indicates failure/false.

Quick Command Recipes

Run a script

cmd "build.mxcmd"

Preview script tokens

tokenize "build.mxcmd"

Create AST HTML

visual "build.mxcmd" "build_ast.html"

Regex text cleanup

regex_replace "[^a-zA-Z0-9]" "_" value

Find Command

Search commands:

exec

Execute an external shell command and return its output as text. This is the primary bridge between MXCMD and system shell tools.

Usage

exec "ls"

Example

files = $(exec "ls | sort")

random_shader

Apply a random shader effect in console GUI mode.

Usage

random_shader

default_shader

Reset shader effect to the default rendering mode in console GUI mode.

Usage

default_shader

set_shader

Load and apply a custom shader file in console GUI mode.

Usage

set_shader "path/to/shader.glsl"

clear

Clear the current console output buffer.

Usage

clear

help

Show built-in help for shell commands.

Usage

help

about

Display runtime information about the shell build and environment.

Usage

about

wsl_on / wsl_off

Enable or disable WSL command routing on supported Windows builds.

Usage

wsl_on
wsl_off

argv

Access command-line arguments passed to the current script or invocation context.

Usage

argv index
argv "length"
argv "all"

exit

Terminate the shell immediately.

Usage

exit

echo

Prints its arguments to standard output, expanding any variables.

Usage

echo [ARG]...

Arguments

Example

echo Hello USER

cat

Concatenates and displays file contents, or reads from standard input if no files are specified.

Usage

cat [FILE]...

grep

Searches input or files for lines matching a pattern, optionally using regular expressions.

Usage

grep [--r|--e] PATTERN [FILE]...

Options


print

Print arguments line-by-line. Supports optional numeric formatting modes for integer/float output.

Usage

print [--i|--f] ARG...

cd

Change the shell’s current working directory.

Usage

cd DIR

list (ls)

List the contents of a directory.

Usage

ls [DIR]

sort

Sorts lines of text from files or standard input.

Usage

sort [FILE]...

find

Recursively search a directory tree for filenames containing a given pattern.

Usage

find PATH PATTERN

pwd

Print the current working directory.

Usage

pwd

mkdir

Create new directories.

Usage

mkdir [--p] DIR...

Options


cp

Copy files or directories.

Usage

cp [--r] SOURCE... DEST

mv

Rename or move files and directories.

Usage

mv SOURCE... DEST

touch

Update file timestamps or create files if they do not exist.

Usage

touch FILE...


tail

Display the last part of files or input.

Usage

tail [--n N] [FILE]...

wc

Count lines, words, and characters in files or input.

Usage

wc [--l] [--w] [--c] [FILE]...

sed

Perform basic stream editing via substitution expressions.

Usage

sed [options] 's/pattern/replacement/[g]' [FILE]

Options


printf

Formatted printing, similar to C's printf.

Usage

printf FORMAT [ARG]...

test

Evaluate conditional expressions for use with if, while, and boolean branching. Returns 0 for true and non-zero for false.

Usage

test ARG...

Example

if test count --gt 10
then
    echo "large dataset"
fi

cmd

Execute an MXCMD script file within the current shell runtime. Useful for modular scripts and task automation.

Usage

cmd SCRIPT_FILE

Example

cmd "./scripts/deploy.mxcmd"

visual

Render a script's abstract syntax tree (AST) into an HTML visualization for debugging parser/structure issues.

Usage

visual SCRIPT_FILE OUTPUT_HTML

Example

visual "build.mxcmd" "build_ast.html"

at

Extract an element by index from a newline-separated list.

Usage

at LIST INDEX

len

Count items in a list, either by lines or words.

Usage

len LIST

index

Extract a substring by start position and length.

Usage

index STRING START LENGTH

strlen

Get the length of a string.

Usage

strlen STRING

strfind

Find the position of a substring within a string.

Usage

strfind START STRING SEARCH

strfindr

Find the position of a substring within a string, searching from the right (end of string).

Usage

strfindr STRING SEARCH

strtok

Split a string into tokens using a delimiter and return the result as a newline-separated list.

Usage

strtok STRING DELIMITER

extern

Register an external function from a shared library as a command.

Usage

extern LIBRARY FUNCTION COMMAND_NAME

Example

check the source code for how to use libmxcmd to create a shared library. Then say named libmath.so with a function add_numbers:
extern "math" "add_numbers" "add"

List Management Commands

Named list helpers for dynamic collections, temporary buffers, token streams, and script-level data manipulation.


rand

Generate a pseudo-random number between MIN and MAX (inclusive), useful for randomized logic and procedural scripts.

Usage

rand MIN MAX

Example

rand 1 100  # Generates a random number between 1 and 100

expr

Evaluate expressions and return computed values. Supports arithmetic, comparison, and logical operators.

Usage

expr EXPRESSION

Example

expr "5 + 3 * 2"      # Returns 11
expr "10 > 5 && 3 < 4"  # Returns 1 (true)

commands

List all available commands in the shell, including built-in, user-defined, and externally loaded commands.

Usage

commands

Debug Commands

getline

Read one full line from standard input and assign it to a variable.

Usage

getline variable

Example

printf "enter input: " && getline value

regex_match

Check whether the entire string matches a regular expression pattern.

Usage

regex_match PATTERN STRING

Example

if test $(regex_match "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$" email) --eq "1"
then
    echo "Valid email format"
fi

regex_replace

Replace every region matching a regular expression pattern with a replacement string.

Usage

regex_replace PATTERN REPLACEMENT STRING

Example

sanitized = $(regex_replace "[^a-zA-Z0-9]" "_" string)


regex_split

Split a string using a regular-expression delimiter and return a newline-separated token list.

Usage

regex_split PATTERN STRING

Example

parts = $(regex_split "," "a,b,c" )

tokenize

Run the MXCMD scanner/lexer and print the token stream for a source file. Useful for parser debugging and syntax troubleshooting.

Usage

tokenize "filename.mxcmd"

Example

tokens = $(tokenize "build.mxcmd")