How to use * with backticks


#1

I cannot figure out how to run the shell command “ls data/*.sol” using Julia’s backtick mechanism. The obvious

run(ls data/*.sol)

produces

ls: data/*: No such file or directory
ERROR: failed process: Process(ls 'data/*', ProcessExited(1)) [1]


#2

Sorry, somehow the backticks didn’t make it into

run(ls data/*.sol)


#3

run doesn’t run a shell unless you explicitly ask it to. Try

run(`sh -c ls data/*.sol`)

#4

It’s really not recommended to use run(`sh -c ....`) because it opens you up to all of the quoting problems, security holes, and general confusion of shell interpolation. See: A small package to run string as shell command and Quoting in shell commands


#5

You can do file globbing without the shell using

and interpolate the resulting list of files into a backtick expression.


#6

Thanks, that’s what I was looking for.

Perhaps the section “Running External Programs” of the manual could mention the (shell) globbing issue?