Reference for MXCMD literals, assignment, operators, redirection, and command substitution patterns.
42, 3.14"hello" or 'world' All strings like file paths have to be surrounded in quotes.var_name = expression
--var_name # decrement
var_name-- # decrement (postfix)
++var_name # increment
var_name++ # increment (postfix)
Arithmetic: +, -, *, /, %
Unary: prefix -, ++, --; postfix ++, --
cmd1 | cmd2 | cmd3cmd > file, cmd >> filecmd < fileuse && and || for boolean logic
pwd && pwd
ls || pwd
define (param1, param2, ...) # define a new command
begin
statements
return 0 # return a value 0 success non zero failure
end # end of definition
Command substitutions allow you to capture the output of a command and use it as a value. They are denoted by $(command) syntax.
files = $(ls)
count = $(exec "wc -l < \"data.txt\"")
today = $(exec "date \"+%Y-%m-%d\"")
Command substitutions can be used directly as arguments to other commands:
# Use ls output as an argument to another command
cat $(exec "ls | grep \"\.txt$\" | head -n1")
# Use command substitution in file operations
cp important.txt $(printf "backup_%s.txt" $(exec "date \"+%Y%m%d\""))
# Use in user-defined commands
list_files $(pwd)
Command substitutions can be nested to create complex expressions:
d substitution for dynamic file naming
report = $(cat $(printf "logs/log_%s.txt" $(exec "date \"+%Y%m%d\"")))
# Complex example with multiple levels of nesting
fileext = $(exec $(printf "stat -f \"%%SB\" -t \"%%Y.%%m.%%d\" %s" $(exec "ls | head -n1")))
$() is executed in a subshell
define count_text(dir, ext)
begin
total = 0.000000
for f in $(ls | sort)
do
path = $(printf "%s/%s" dir f)
pos = $(strfind 0.000000 path ext)
if test pos --ne -1.000000
then
count = $(wc --l path)
total = total + count
printf "File: %s has %d lines\n" path count
fi
done
printf "total lines: %d\n" total
end