# Is there any way to run an external command with \* in it?

**URL:** <https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926>\
**Category:** General Usage\
**Created:** [January 2, 2022, 12:55pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926 "2022-01-02T12:55:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 2, 2022, 12:55pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926/1 "2022-01-02T12:55:04Z")

</div>

Hello

I am trying to run an external command "rsync \* a: " with run() and the \* makes it impossible. there is an old unresolved question on this. [How to quote special characters in run() function](https://discourse.julialang.org/t/how-to-quote-special-characters-in-run-function/21359)

I am now making a detour to R to make it happen  
R"  
system(“rsync \* a:”)  
"  
but that seems very inelegant.

Is there a way to do this natively in Julia?

best regards, Jack

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [January 2, 2022, 1:00pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926/2 "2022-01-02T13:00:40Z")

</div>

You can use the [Glob.jl](https://github.com/vtjnash/Glob.jl) package:

```julia
run(`rsync $(glob("*")) a:`)

```

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 2, 2022, 1:16pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926/3 "2022-01-02T13:16:38Z")

</div>

Thanks fredrikekre!

That worked brilliantly! And I would never have thought of that usage of glob.

best, Jack

---

<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:** [January 2, 2022, 1:24pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926/4 "2022-01-02T13:24:22Z")

</div>

> [@JackStrauss](#):
>
> I am trying to run an external command "rsync \* a: " with run() and the \* makes it impossible.

The problem is not quoting or “special characters”. You can do `run(`rsync "*" a:"`)` which passes the `*` to `rsync` just fine. However, it looks like you don’t actually want to pass `*` to `rsync` — you want `*` expansion ([globbing](https://en.wikipedia.org/wiki/Glob_(programming))), but this is performed by the _shell_ and Julia’s `run` does not invoke the shell — it runs `rsync` _directly_.

If you want to run `rsync` via a shell, you can do so by directly invoking `sh -c`, i.e.:

```julia
run(`sh -c "rsync * a:"`)

```

(Invoking a shell is what R’s `system` function is doing.)

However, invoking the shell is a suboptimal approach in general. Not only is it slower (first the system launches a `sh` process, then `sh` launches `rsync`), but it also runs into lots of brittle issues with quoting. (And there are portability problems, e.g. on Windows.)

That’s why we generally recommend pure-Julia alternatives to shell features, like the Glob.jl package if you want to do glob expansion of paths, or Julia’s `pipeline` function if you want to pipe.

---

<div class="post-metadata">

**Author:** ![JackStrauss](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Post date:** [January 2, 2022, 1:39pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-run-an-external-command-with-in-it/73926/5 "2022-01-02T13:39:12Z")

</div>

Thanks stevengj

That makes perfect sense to me. I am indeed globbing and it works as it should with Glob.jl.

all the best, Jack
