$Scalar
Sigil (eg variables)Expand values as a scalar
The scalar token is used to tell Murex to expand variables and sub-shells as a string (ie one single parameter) irrespective of the data that is stored in the string.
One common use case where Murex’s approach is better is with file names. Traditional shells would treat spaces as a new file. Whereas Murex treats spaces as any other printable character character.
There are two basic syntaxes. Bare and enclosed.
Bare syntax looks like the following:
$scalar
The variable token must be followed with one of the following characters: alpha (a
to z
, upper and lower case), numeric (0
to 1
), underscore (_
) and/or a full stop (.
).
Enclosed syntax looks like the following:
$(scalar)
Enclosed syntax supports any unicode characters however the variable name needs to be surrounded by parenthesis. See examples below.
» $example = "foobar"
» out $example
foobar
Variable names can be non-ASCII however they have to be surrounded by parenthesis. eg
» $(比如) = "举手之劳就可以使办公室更加环保,比如,使用再生纸。"
» out $(比如)
举手之劳就可以使办公室更加环保,比如,使用再生纸。
Sometimes you need to denote the end of a variable and have text follow on:
» $partial_word = "orl"
» out "Hello w$(partial_word)d!"
Hello world!
Please note the new line (\n
) character. This is not split using $
:
» $example = "foo\nbar"
Output as a scalar ($
):
» out $example
foo
bar
Output as an array (@
):
» out @example
foo bar
Scalar:
» out ${ %[Mon..Fri] }
["Mon","Tue","Wed","Thu","Fri"]
Array:
» out @{ %[Mon..Fri] }
Mon Tue Wed Thu Fri
out
will take an array and output each element, space delimited. Exactly the same howecho
would in Bash.
If a variable is used as a commend then Murex will just print the content of that variable.
» $example = "Hello World!"
» $example
Hello World!
Strings and sub-shells can be expanded inside double quotes, brace quotes as well as used as barewords. But they cannot be expanded inside single quotes.
» set example="World!"
» out Hello $example
Hello World!
» out 'Hello $example'
Hello $example
» out "Hello $example"
Hello World!
» out %(Hello $example)
Hello World!
However you cannot expand arrays (@
) inside any form of quotation since it wouldn’t be clear how that value should be expanded relative to the other values inside the quote. This is why array and object builders (%[]
and %{}
respectively) support array variables but string builders (%()
) do not.
ja
): A sophisticated yet simply way to build a JSON arrayset
): Define a variable (typically local) and set it’s valueout
): Print a string to the stdout with a trailing new line character"Double Quote"
: Initiates or terminates a string (variables expanded)%(Brace Quote)
: Initiates or terminates a string (variables expanded)'Single Quote'
: Initiates or terminates a string (variables not expanded)(brace quote)
: Write a string to the stdout without new line (deprecated)@Array
Sigil: Expand values as an arraylet
: Evaluate a mathematical function and assign to variable (deprecated)~
Home Sigil: Home directory path variableThis document was generated from gen/parser/variables_doc.yaml.
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 Tue Dec 10 22:56:57 UTC 2024 against commit 60f05a260f05a227caf73dd5b3478e3cb3f4bb24e46745b.
Current version is 6.4.1005 (develop) which has been verified against tests cases.