# Quoting in shell commands

**URL:** <https://discourse.julialang.org/t/quoting-in-shell-commands/6781>\
**Category:** General Usage\
**Tags:** shell\
**Created:** [October 30, 2017, 5:04pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781 "2017-10-30T17:04:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 30, 2017, 5:04pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/1 "2017-10-30T17:04:03Z")

</div>

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 [...]

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 30, 2017, 5:57pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/2 "2017-10-30T17:57:17Z")

</div>

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](https://github.com/vtjnash/Glob.jl) to get the globbing behavior without going through the shell.

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [October 30, 2017, 6:02pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/3 "2017-10-30T18:02:24Z")

</div>

Or use:

```julia
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"

```

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 30, 2017, 6:03pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/4 "2017-10-30T18:03:54Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 30, 2017, 6:12pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/5 "2017-10-30T18:12:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![harven](https://avatars.discourse-cdn.com/v4/letter/h/3da27b/32.png) [@harven](https://discourse.julialang.org/u/harven)\
**Post date:** [October 30, 2017, 6:46pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/6 "2017-10-30T18:46:27Z")

</div>

Indeed. I must be confusing with the pipes.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 6, 2025, 3:04pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/7 "2025-05-06T15:04:32Z")

</div>

2 posts were split to a new topic: [Removing directory contents recursively](https://discourse.julialang.org/t/removing-directory-contents-recursively/128761)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 6, 2025, 3:23pm UTC](https://discourse.julialang.org/t/quoting-in-shell-commands/6781/8 "2025-05-06T15:23:36Z")

</div>

A post was merged into an existing topic: [Removing directory contents recursively](https://discourse.julialang.org/t/removing-directory-contents-recursively/128761/3)
