Language Guide: Quick start guide for Bash developers

This is a cheat sheet reference for lazy Bash developers wishing to accelerate their introduction into murex:

Piping and redirection

murex supports the | pipe just like Bash but the preferred pipe token in murex the arrow, -> (those two token are interchangeable).

Redirection of stdout and stderr is very different in murex. There is no support for the 2> or &1 tokens, instead you name the pipe as the first parameter:

err: <!out> "error message redirected to stdout"
out: <err> "output redirected to stderr"

You can also use named pipes this way to join up parts of the script that otherwise wouldn’t be part of the same pipeline. See GUIDE.syntax for more details on named pipes.

To redirect to a file you can use the > or >> functions. They work similarly to bash except that they are functions rather than tokens. This means they literally work like the following:

out: "message" -> >  new-file.txt
out: "message" -> >> append-file.txt

However this is clearly ugly in practice. So the following syntactic sugar is supported, |> for overwrite and >> for append:

out: "message" |> new-file.txt
out: "message" >> append-file.txt

Emendable sub-shells

There are two types of emendable sub-shells: strings and arrays.

Examples:

ls -l ${out: file name}           # works because file name contain space
ls -l @{out: file1 file2 file3}   # fails because not an array
ls -l @{out: file1\nfile2\nfile3} # works because output is an array

The reason murex breaks from the POSIX tradition of using backticks and parentheses is because murex works on the principle that everything inside a curly bracket is considered a new block of code. Typically that would mean a sub-shell however sometimes it could be configuration code in the form of inlined JSON.

Globbing

There isn’t auto-expansion of globbing to protect against accidental damage. Instead globbing is achieved via sub-shells using either:

Examples:

# all text files via globbing:
ls -l @{g *.txt}

# all text and markdown files via regexp:
ls -l @{rx '\.(txt|md)$'}

# all files via type matching:
ls -l @{f +f}

You can also using type matching against globbing and regexp to filter out types in conjunction with file name matching:

# all directories named *.txt
ls -l @{g *.txt -> f +d}

Exit code

In bash the variable $? would store the exit code. This doesn’t exist in murex. Instead there a separate command exitnum:

open: test/fox.txt -> grep: foobar; exitnum

Array expansion

In bash you can expand arrays using the following syntax: a{1..5}b. In murex this is another sub-shell process: a: a[1..5]b. As you can see, murex also uses square brackets instead as well. There are a few other changes, read GUIDE.arrays-and-maps for more on using the array builtin.

Back ticks

In murex back ticks do not spawn sub-shells. Back ticks are treated like a regular, printable, character. Their only special function is quoting strings in =, eg:

if { = `quoted string`==variable } { out "do something" }

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Thu Oct 13 08:08:18 UTC 2022 against commit ed6b6fced6b6fc609f4be93c5d3348695a762facfecf48f.

Current version is 2.11.2200 which has been verified against 16798 tests cases.