Skip to main content

Rosetta Stone

Laurence MorganAbout 5 min

Rosetta Stone

A tabulated list of Bashism's and their equivalent Murex syntax

Rosetta stone

Below is a reference table of common Bash code and how it could be written in Murex.

It is also recommended that you read the language tour if you want to learn more about shell scripting in Murex.

Output & error streams

Write to STDOUTecho "Hello Bash"out "Hello Murex"

echo "Hello Murex" [1]
Write to STDERRecho "Hello Bash" >2err "Hello Murex"
Write to file (truncate)echo "Hello Bash" > hello.txtecho "Hello Murex" |> hello.txt
Write to file (append)echo "Hello Bash" >> hello.txtecho "Hello Murex" >> hello.txt
Pipe commandsecho "Hello Bash | grep Bashecho "Hello Murex | grep Murex

out "Hello Murex" -> regexp m/Murex/
Redirect errors to STDOUTcurl 2>&1 | lesscurl ? less

curl <!out> | less
Redirect output to STDERRuname -a >&2uname <err> -a
Ignore STDERR outputecho something 2>/dev/nullecho <!null> something
Output ANSI colors and stylesecho -e "\n\032[0m\033[1mComplete!\033[0m\n"out "{GREEN}{BOLD}Complete!{RESET}"

Quoting strings

Infixingecho "Hello $SHELL"out "Hello $SHELL"
String literalsecho 'Hello' $SHELLout 'Hello' $SHELL
Nesting quotesecho 'Hello \'Bob\''out %(Hello 'Bob')

Process management

Exit number$?exitnum
Background jobscommand &bg { command }
Job controlps,
bg pid,
fg pid
bg fid,
fg fid
Happy pathscommand && commandcommand && command

try {command; command}
Unhappy pathscommand || commandcommand || command

try {command}; catch {command}
Pipe failset -o pipefailrunmode trypipe module

runmode trypipe function

trypipe { commands }


Single line# comment# comment
Multiple lines:<<EOC
line 1
line 2
line 1
line 2
Mid-linen/aeg out foo/#comment#/bar

File pattern matching

(also known as "wildcards")

Globbingeg ls *.txteg ls *.txt (in the interactive terminal)

g pattern

eg ls @{g *.txt}
Regexpn/arx pattern

eg ls @{rx '*\\.txt'}
File type matchingn/af flags

eg f +s (only return symlinks)
Chainingn/aeg f +f | g *.txt | !g murex.*
(returns only files with the extension "txt" that aren't called "murex")


Assignmentfoobar = $((1 + 2 * 3))foobar = 1 + 2 * 3 [2]
Comparison, string[ "$(command parameters...)" == "value" ]command(parameters...) == "value" [2] [7]

${command parameters...} == "value" [2] [5]
Comparison, numeric[ $integer -eq 5 ]$number == 5 [2]
Arithmeticecho $(( 1+2*3 ))1 + 2 * 3 [2]

out (1+2*3) [2] [5]
Supported data types1. String,
2. Integer
(all variables are strings)
1. String,
2. Integer,
3. Float (default number type),
4. Boolean
5. Array,
6. Object,
7. Null
(all variables can be treated as strings and/or their primitive)


Assign a local variablelocal foo="bar"$foo = "bar" [2] [6]

out "bar" | set $foo
Assign a global variablefoo="bar"$ = "bar" [6]

out "bar" | global $foo
Assign an environmental variableexport foo="bar"export foo = "bar" [1] [2] [3]

$ = "bar" [6]

out "bar" | export $foo [3]
Printing a variableecho "$foobar"out $foobar [5]


(variables don't need to be quoted in Murex)


(eg arrays, lists)

Creating an arrayarray_name=(value1 value2 value3)%[value1 value2 value3]

%[value1, value2, value3]

eg array_name = %[1, 2, 3],
eg %[hello world] | foreach { ... }
Accessing an array element${array_name[0]}$array_name[0] (immutable)

$array_name.0 (mutable) [5]

array | [0]
Printing multiple elementsecho ${array_name[1]} ${array_name[0]}@array_name[1 0]

array | [1 0]
Printing a range of elementsn/a@array_name[1..3]

array | [1..3]
Printing all elementsecho ${array_name[*]}@array_name
Iterating through an arrayfor item in array; do;
array | foreach item { $item }

eg %[Tom Richard Sally] | foreach name { out "Hello $name" }


(eg JSON objects, maps, hashes, dictionaries)

Creating an objectn/a%{ key: value, array: [1, 2, 3] } [2]

eg object_name = %{ key: val, arr: [1,3,3] }
eg %{ a:1, b:2, c:3 } | formap { ... }
Accessing an elementn/a$object_name[key] (immutable)

$object_name.key [5] (mutable)

object | [key]
Printing multiple elementsn/a$object_name[key1 key2]

object | [key1 key2]
Accessing a nested elementn/a$object_name[[]] (immutable) [4]

$ (mutable)

object | [[]] [4]

Iterating through an mapn/aobject | formap key value { $key; $value }

eg %{Bob: {age: 10}, Richard: {age: 20}, Sally: {age: 30} } | formap name person { out "$name is $person[age] years old" }


Sub-shell, string"$(commands)"

eg "echo $(echo "Hello world")"
${commands} [5]

eg out ${out Hello world}
Sub-shell, arrays$(commands)

eg $(echo 1 2 3)
@{commands} [5]

eg out @{ %[1,2,3] }
In-lined functionsn/afunction(parameters...) [7]

eg out uname(-a)

Common one-liners

Add $PATH entriesexport PATH="$PATH:/usr/local/bin:$HOME/bin"The same Bash code works in Murex too. However you can also take advantage of Murex treating $PATH as an array

%[ @PATH /usr/local/bin "$HOME/bin" ] | format paths | export $PATH
Iterate directoriesfor i in $(find . -maxdepth 1 -mindepth 1 -type d); do
    echo $i
f +d | foreach $dir {
    out $i
If $dir exists...if [ -d "$dir" ]; then
    # exists
if { g $dir | f +d } then {
    # exists
Print current directoryresult=${PWD##*/}; result=${result:-/}; printf '%s' "${PWD##*/}" (read moreopen in new window)$PWD[-1]


  1. Supported for compatibility with traditional shells like Bash.
  2. Unlike Bash, whitespace (or the absence of) is optional.
  3. Environmental variables can only be stored as a string. This is a limitation of current operating systems.
  4. Path separator can be any 1 byte wide character, eg /. The path separator is defined by the first character in a path.
  5. Murex uses ${} for subshells and $() for variables, the reverse of what Bash and others use. The reason for this difference is because {} always denotes a code block and () denotes strings. So ${foobar} makes more sense as a subshell executing the command foobar, while $(foobar) makes more sense as the variable $foobar.
  6. When assigning a variable where the right hand side is an expression, eg $foo = "bar", the dollar prefix is optional. The set, global and export keywords are considered deprecated.
  7. The command(parameters...) only works for commands who's names match the following regexp pattern: [._a-zA-Z0-9]+. Which is exclusively uppercase and lowercase English letters, numbers, fullstop / period, and underscore.

See Also

This document was generated from gen/user-guide/rosetta-stone_doc.yamlopen in new window.

Last update:
Contributors: Laurence Morgan