# Using \* as a wildcard in backtick commands

**URL:** <https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094>\
**Category:** General Usage\
**Created:** [September 26, 2017, 5:21pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094 "2017-09-26T17:21:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dehann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dehann/32/2003_2.png) [@dehann](https://discourse.julialang.org/u/dehann)\
**Post date:** [September 26, 2017, 5:21pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/1 "2017-09-26T17:21:45Z")

</div>

Hi, I have seem to have a more intricate issue with backticks and string interpolation, and not sure what you mean by ‘command syntax’?

To compile several java .class files into one .jar files, I need to do:

```julia
run(`jar cf dest.jar folder/*.class`)

```

The issue is that the `*` character gets picked up by Julia and introduces single quotes, which in turn disrupts the `jar` process with an error:

```julia
failed process: Process(`jar cf dest.jar 'folder/*.class'`, ProcessExited(1))

```

However, by hand I am able to run without the awkward single quotes just fine.

```bash
jar cf dest.jar folder/*.class

```

The issue is that I need all the `*.class` files in one `.jar` file, which are generated from a Julia process. This automated single quoting seems a bit tricky in this situation… I think the documentation motivates the case of working around spaces in file names, but maybe a `funny\ filename.txt` would be an alternative solution rather than an automated `'funny filename.txt'`?

Is there a workaround to avoid the introduction of single quotes? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 26, 2017, 9:34pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/2 "2017-09-26T21:34:25Z")

</div>

You need to explicitly expand globbing using the [`Glob.jl` package](https://github.com/vtjnash/Glob.jl).

---

<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:** [September 26, 2017, 10:43pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/3 "2017-09-26T22:43:10Z")

</div>

To expand on that, the reason this doesn’t work is that expanding `*` to match any file in the directory is something that your _shell_ (generally bash) does for you. Julia commands are not run by the shell at all, but are just executed directly (see [https://docs.julialang.org/en/stable/manual/running-external-programs/#Running-External-Programs-1](https://docs.julialang.org/en/stable/manual/running-external-programs/#Running-External-Programs-1) , specifically the third bullet point).

This also explains why bash aliases and shell functions can’t be used inside commands (unless your command itself launches bash and passes some string to bash to execute). See also [Success() does not give same result as running in terminal](https://discourse.julialang.org/t/success-does-not-give-same-result-as-running-in-terminal/1958) and [Getting Unwanted Quotes in System Calls](https://discourse.julialang.org/t/getting-unwanted-quotes-in-system-calls/2451)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 27, 2017, 3:55pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/4 "2017-09-27T15:55:51Z")

</div>

There’s a plan to add more shell-like features to backticks in the future, which is why we’ve deprecated unquoted/unescaped shell metacharacters in backticks in 0.6. In the future this kind of globbing may be built in, and Julia will effectively implement a basic portable shell in backticks, including pipelines, I/O redirection and probably globbing and home directory expansion. It would also allow cool things like splicing a Julia task into a pipeline or reading to/from arbitrary Julia I/O objects. I was going to try to do this for 1.0 but realized that it was a ton of work and can be added in 1.x now that we’ve deprecated shell metacharacters.

---

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [September 27, 2017, 9:17pm UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/5 "2017-09-27T21:17:17Z")

</div>

Some time ago, I wanted shell-like functionality for Julia’s backtick commands.  
So I wrote a small convenience module to help.  
It uses command literals.

```julia
run(sh`jar cf dest.jar folder/*.class`)

```

Also supports `cmd` and `ps` (powershell) on Windows.

```julia
Julia-0.6.0> sh`jar cf dest.jar folder/*.class`
`sh -c 'jar cf dest.jar folder/*.class'`

Julia-0.6.0> cmd`jar cf dest.jar folder/*.class`
`cmd /s /c '"jar cf dest.jar folder/*.class"'`

Julia-0.6.0> ps`jar cf dest.jar folder/*.class`
`powershell -Command 'jar cf dest.jar folder/*.class'`

```

And if anyone is interested, here’s the module:

```julia
__precompile__ ()

module ShellCommands

export @cmd_cmd, @ps_cmd, @busybox_cmd, @sh_cmd

macro cmd_cmd(s_str)
    s_expr = parse(string('"', escape_string(s_str), '"'))
    return esc(:(Cmd(Base.cmd_gen(("cmd", "/s", "/c", string('"', $s_expr, '"'))), windows_verbatim=true)))
end

macro ps_cmd(s_str)
    s_expr = parse(string('"', escape_string(s_str), '"'))
    return esc(:(Base.cmd_gen(("powershell", "-Command", $s_expr))))
end

macro busybox_cmd(s_str)
    s_expr = parse(string('"', escape_string(s_str), '"'))
    return esc(:(Base.cmd_gen(("busybox", "sh", "-c", $s_expr))))
end

macro sh_cmd(s_str)
    s_expr = parse(string('"', escape_string(s_str), '"'))
    return esc(:(Base.cmd_gen(("sh", "-c", $s_expr))))
end

end

```

---

<div class="post-metadata">

**Author:** ![jacob-roth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacob-roth/32/1862_2.png) [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Post date:** [March 27, 2019, 12:45am UTC](https://discourse.julialang.org/t/using-as-a-wildcard-in-backtick-commands/6094/6 "2019-03-27T00:45:01Z")

</div>

Thanks a lot, just came across this! A `v1.x` follow up for posterity: the `parse` commands will be replaced with `Meta.parse`
