# Can't quote a Cmd with equals sign correctly

**URL:** <https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963>\
**Category:** General Usage\
**Tags:** drwatson\
**Created:** [August 6, 2021, 7:22pm UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963 "2021-08-06T19:22:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [August 6, 2021, 7:22pm UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/1 "2021-08-06T19:22:23Z")

</div>

I’ve been happily using DrWatson for my latest project, using its convention for filenames. For example, if my simulation uses parameters `Dict(:a=>2, :b=>7)`, my output data file might be named `simulation_a=2_b=7.h5`.

But now the problem comes when I need to call a shell command from julia with one of these files. For example, I might want to run a shell command that is equivalently given by any of the following three options:

```bash
h5ls "simulation_a=2_b=7.h5"
h5ls 'simulation_a=2_b=7.h5'
h5ls simulation_a\=2_b\=7.h5

```

**_Either_ the filename itself should be surrounded by exactly one set of single or double quotes _or_ each `=` should be escaped — not both quotes and escapes, and not two kinds of quoting.**

The problem is when I try to make a `Cmd` to do these things; julia appears to be too clever for me, giving me either no quoting and no escaping, or quoting and escaping. These are some of the options I’ve tried (all of which fail):

```julia
julia> `h5ls simulation_a\=2_b\=7.h5`
`h5ls simulation_a=2_b=7.h5`

julia> `h5ls 'simulation_a=2_b=7.h5'`
`h5ls simulation_a=2_b=7.h5`

julia> `h5ls "simulation_a=2_b=7.h5"`
`h5ls simulation_a=2_b=7.h5`

julia> `h5ls "simulation_a\=2_b\=7.h5"`
`h5ls 'simulation_a\=2_b\=7.h5'`

julia> `h5ls "simulation_a\\=2_b\\=7.h5"`
`h5ls 'simulation_a\=2_b\=7.h5'`

julia> `h5ls simulation_a\\=2_b\\=7.h5`
`h5ls 'simulation_a\=2_b\=7.h5'`

julia> Cmd(["h5ls", "simulation_a=2_b=7.h5"])
`h5ls simulation_a=2_b=7.h5`

julia> Cmd(["h5ls", "'simulation_a=2_b=7.h5'"])
`h5ls "'simulation_a=2_b=7.h5'"`

julia> Cmd(["h5ls", "simulation_a\\=2_b\\=7.h5"])
`h5ls 'simulation_a\=2_b\=7.h5'`

```

Is there any way to achieve my goal?

(To make matters worse, I actually want to pass an array of files to a shell command…)

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 6, 2021, 7:53pm UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/2 "2021-08-06T19:53:12Z")

</div>

`run(Cmd(["h5ls", "simulation_a=2_b=7.h5"]))`

Personally, I avoid tricky characters, such as `=`, in filenames.

---

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [August 6, 2021, 8:12pm UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/3 "2021-08-06T20:12:45Z")

</div>

> [@hendri54](#):
>
> Cmd([“h5ls”, “simulation\_a=2\_b=7.h5”])

That gives me `h5ls simulation_a=2_b=7.h5`, which is not what I need.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [August 7, 2021, 3:08am UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/4 "2021-08-07T03:08:44Z")

</div>

You don’t want a shell command, you want a system command. You don’t need to do shell quoting if there is no shell.

```julia
julia> `h5ls simulation_a=2_b=7.h5` |> dump
Cmd
  exec: Array{String}((2,))
    1: String "h5ls"
    2: String "simulation_a=2_b=7.h5"
  ignorestatus: Bool false
  flags: UInt32 0x00000000
  env: Nothing nothing
  dir: String ""

```

---

<div class="post-metadata">

**Author:** ![moble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moble/32/23535_2.png) [@moble](https://discourse.julialang.org/u/moble)\
**Post date:** [August 7, 2021, 3:44am UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/5 "2021-08-07T03:44:48Z")

</div>

Sorry. I misunderstood one of the error messages I was getting:

```julia
IOError: could not spawn `h5ls simulation_a=2_b=7.h5`: no such file or directory (ENOENT)

```

The “file or directory” it’s talking about is not the file I was talking about; it’s the `h5ls` command. I happened to test these things only with binaries that are in my own PATH, but not whatever `run` is using.

So yes, this works just fine. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Barget](https://avatars.discourse-cdn.com/v4/letter/b/94ad74/32.png) [@Barget](https://discourse.julialang.org/u/Barget)\
**Post date:** [March 3, 2022, 10:50am UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/6 "2022-03-03T10:50:52Z")

</div>

Hello,

Same issue here, but with an additional quirk. The command I want to run is:

```julia
ffmpeg -f dshow -i video="HP HD Camera" -f rtsp rtsp://127.0.0.1:8554/live

```

The double quotes are needed, as for the equal sign without space.

When I type directly the command, I get:

```julia
julia> cmd = `ffmpeg -f dshow -i video="HP HD Camera" -f rtsp rtsp://127.0.0.1:8554/live`
`ffmpeg -f dshow -i 'video=HP HD Camera' -f rtsp rtsp://127.0.0.1:8554/live`

```

Escaping the double quotes is not better:

```julia
julia > cmd = `ffmpeg -f dshow -i video=\"HP HD Camera\" -f rtsp rtsp://127.0.0.1:8554/live`
`ffmpeg -f dshow -i 'video="HP' HD 'Camera"' -f rtsp rtsp://127.0.0.1:8554/live`

```

Any ideas?

> **PS**
>
> PS: I’m aware of FFMPEG.jl, but I need to keep the pipe open, so I went with a lower-lever approach. Suggestions are welcome.  
> PPS: Edits are for formatting & typos

---

<div class="post-metadata">

**Author:** ![cjdoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjdoris/32/213133_2.png) [@cjdoris](https://discourse.julialang.org/u/cjdoris)\
**Post date:** [March 3, 2022, 12:26pm UTC](https://discourse.julialang.org/t/cant-quote-a-cmd-with-equals-sign-correctly/65963/7 "2022-03-03T12:26:09Z")

</div>

The first thing you tried was actually correct, `x="y z"`, `"x=y z"` and `'x=y z'` are all the same to a shell.

AFAIK command strings use the same quoting syntax as any POSIX shell so if it works in sh/bash/zsh then the same command works in Julia.
