Inlined commands for expressions and statements
The traditional way to spawn a sub-shell would be ${}
(or $()
in Bourne Shell and its many derivatives). This works great for inlining entire command lines but it isn’t so convenient if you want to call one command and particularly within an expression.
This is where C-style functions can be more ergonomic. They follow the common structure of command(parameters...)
. For example:
» out("hello world")
The syntax is not exactly like C and its derivatives however:
And unlike statements:
Ostensibly, C-style functions are just syntactic sugar for ${}
. As such, they’re not intended to be used liberally but rather just in instances it improves readability.
As a C-style function (CSF) vs a sub-shell:
# CSF
» $doc = open(README.html)
# Sub-shell
» $doc = ${open README.html}
As a C-style function (CSF) vs a sub-shell:
# CSF
» datetime(--in {now} --out {unix}) / 60
28687556.3
# Sub-shell
» ${datetime --in {now} --out {unix}} / 60
28687556.3
As a C-style function (CSF) vs a sub-shell:
# CSF
» echo It is datetime(--in {now} --out {py}%H) o\' clock
It is 23 o' clock
# Sub-shell
» echo It is ${datetime --in {now} --out {py}%H} o\' clock
It is 23 o' clock
Notice in the example above, echo
’s parameters are not quoted. This is because C-style functions do not support infixing.
Please note that currently the only functions supported are ones who’s names are comprised entirely of alpha, numeric, underscore and/or exclamation marks.
C-style functions do not support being infixed like sub-shells can be:
# CSF
» echo "It is datetime(--in {now} --out {py}%H) o\' clock"
It is datetime(--in {now} --out {py}%H) o' clock
# Sub-shell
» echo "It is ${datetime --in {now} --out {py}%H} o\' clock"
It is 23 o' clock
datetime
: A date and/or time conversion tool (like printf
but for date and time values)echo
: Print a string to the stdout with a trailing new line characterexpr
: Expressions: mathematical, string comparisons, logical operatorsopen
: Open a file with a preferred handlerThis document was generated from gen/parser/c-style-functions_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 Thu Aug 15 14:38:34 UTC 2024 against commit 50ed9d650ed9d6df391240d3c2c02e623636e508dfcdad1.
Current version is 6.2.4000 which has been verified against tests cases.