Quoting in shell commands

I don’t understand the new behavior of the shell wrt quotation.
Assuming that there are files in the current directory starting by img, how do I execute the following shell command from julia?

   $ ls -l img*

The following returns an error because the files are not found. It seems that the wildcard is quoted hence not expanded at the shell.

  julia> run(`ls -l img*`)

Specifying a filename works.

 julia> run(`ls img.45.jpg`)
 -rw-r--r-- 1 [...]
1 Like

Julia commands are run directly, and not passed to a shell, so things like aliases, shell globbing, etc. will not work. You can use https://github.com/vtjnash/Glob.jl to get the globbing behavior without going through the shell.

3 Likes

Or use:

julia> filter!(f -> startswith(f, "Sc"), readdir())
6-element Array{String,1}:
 "Screen Shot 2017-08-28 at 12.33.44.png"
 "Screen Shot 2017-09-28 at 23.31.45.png"
 "Screen Shot 2017-09-28 at 23.43.44.jpg"
 "Screen Shot 2017-09-28 at 23.43.44.png"
 "Screen Shot 2017-09-28 at 23.43.46.png"
 "Screen Shot 2017-09-28 at 23.46.31.png"
1 Like

Ha, ok, so it looks like a major change. The following will do.

  julia> run(`bash -c 'ls -l img-*'`)
1 Like

Major change since when? AFAIK globbing has never been supported in Cmd objects, and I just verified that the code you posted gives the same result in Julia v0.3, v0.4, v0.5, and v0.6.

2 Likes

Indeed. I must be confusing with the pipes.