Julia Language Shell Scripting and Piping Shelling out from Julia code


Julia code can create, manipulate, and execute command literals, which execute in the OS's system environment. This is powerful but often makes programs less portable.

A command literal can be created using the `` literal. Information can be interpolated using the $ interpolation syntax, as with string literals. Julia variables passed through command literals need not be escaped first; they are not actually passed to the shell, but rather directly to the kernel. However, Julia displays these objects so that they appear properly escaped.

julia> msg = "a commit message"
"a commit message"

julia> command = `git commit -am $msg`
`git commit -am 'a commit message'`

julia> cd("/directory/where/there/are/unstaged/changes")

julia> run(command)
[master (root-commit) 0945387] add a
 4 files changed, 1 insertion(+)