Run shell commands becomes easy in Julia!
Author innerlee
10 Stars
Updated Last
1 Year Ago
Started In
September 2017


Build Status Build status

julia> using Shell

appveyor.yml  REQUIRE  src  test

Now you can run string commands in Julia!

Supports cmd, powershell and wsl in Windows!

WARN: The implementation basically put the string into a script file and run that file. So it is error prone because you have to deal with all the subtle stuff like escaping spaces, quotes, etc. This tool is good for running simple things like ls, echo, etc. But do not use this in your serious scripts unless you have double checked its correctness.


julia> using Shell

julia>"echo $SHELL", capture=true)

julia>"for i in dust junk; do echo $i; done")

julia> files = ["temp file 1", "temp file 2"]
2-element Array{String,1}:
 "temp file 1"
 "temp file 2"

julia> filelist = esc`$files.txt`
"'temp file 1.txt' 'temp file 2.txt'"

julia>"touch $filelist")

julia>"touch $(esc`$files.$["txt","md"]`)", dryrun=true)
touch 'temp file 1.txt' 'temp file' 'temp file 2.txt' 'temp file'

julia>"ls > 'temp file 0.txt'")

julia>"cat 'temp file 0.txt' | grep temp")
temp file 0.txt
temp file 1.txt
temp file 2.txt

julia>"rm 'temp file'*")


julia> Pkg.clone("")


  • use esc`your string` to help you escape (not working for cmd in Windows).
  • use dryrun=true to check the command to be run without actually running.
  • Change default shell by calling Shell.setshell("powershell").
  • The output chomps by default. Change this by calling Shell.setchomp(false).
  • In Windows, the code page may be changed to 65001 after running.

More Notes

See the discussions here. (You can use esc`your argmuments` to take advantage of the built-in escaping of Cmd objects, though.) A "better" way is to learn the Cmd object and perhaps the Glob.jl package as pointed out here.