Expressions
Parameter values passed into a CommandBox command don't have to be static. Any part of the parameter which is enclosed in backticks (`) will be evaluated as a CommandBox expression. That means that the enclosed text will be first executed as though it were a separate command and the output will be substituted in its place.
Any valid command can be used as an expression, including calls to native OS binaries, CFML functions, or REPL one-liners. Note that any text that a command immediately flushes to the console during its execution (like a download progress bar) will not be returned by the expression, though it will display on the console.

Entire Parameter

Take for instance, this simple command that prints out the contents of a file:
1
cat defaultServer.txt
Copied!
It can be used as a dynamic parameter like so:
1
server start name=`cat defaultServer.txt`
Copied!
In the example above, the contents of the defaultServer.txt file will be passed in as the value of the "name" parameter to the "server start" command. If the contents of the file was the text myServer, the equivalent final command would be:
1
server start name=myServer
Copied!

Inside Parameters

There can be more than one expression in a single parameter value. Expressions can also be combined with static text and they will all be evaluated in the order they appear:
1
echo "Your CommandBox version is `ver` and this app is called '`package show name`'!!"
Copied!
That would output something similar to:
1
Your CommandBox version is 3.0.0 and this app is called 'Brad's cool app'!
Copied!
If you need to use an actual backtick in a parameter value, escape it with a backslash.
1
echo "Nothing to \`see\` here"
Copied!
Which outputs
1
Nothing to `see` here
Copied!

Express Yourself

This unlocks a new world of scripting potential when combined with other abilities like native OS binary execution and CFML functions from the CLI. Here's some examples to get your gears turning:
Set a package property in box.json equal to the current date passed through a CFML date mask
1
package set createdDate="'`#now | #dateformat mm/dd/yyyy`'"
2
Set createdDate = 1/1/2016
Copied!
Set properties based on manipulations of previous values:
1
package set name=brad
2
Set name = brad
3
package set name="`package show name` wood"
4
Set name = brad wood
Copied!
Perform CFML operations on local files:
1
Commandbox> #hash `cat pass.txt`
Copied!
Execute environment-aware install scripts based on local files. (isProduction.txt would contain the text true or false in this ex.)
1
install id=coldbox production=`cat /home/user/isProduction.txt`
Copied!
Last modified 8mo ago