# Spaces in arguments when running in cygwin shell?

**URL:** <https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893>\
**Category:** General Usage\
**Created:** [January 21, 2019, 8:04pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893 "2019-01-21T20:04:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [January 21, 2019, 8:04pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893/1 "2019-01-21T20:04:53Z")

</div>

I’m calling julia from the command line in a cygwin shell and ran into the following problem…

```julia
julia argtest.jl -f '\\foo\bar\this baz.txt'
argtest
["-f", "\\\\foo\\bar\\this", "baz.txt"]
too many arguments

```

you can see that julia is breaking up the second argument at the space.  
(edit: i’m simply printing ARGS

however if i write a quick bash script:

```julia
#!/bin/bash

printf "\"%s\"\n" "$1"

```

I get the expected result

```julia
$ . argtest.sh '\\foo\bar\this\ baz.txt'
"\\foo\bar\this\ baz.txt"

```

I also created a C program and it does the right thing, i.e. it sees the argument as a single argument.

So I’m unsure where to go from here. Julia-under-windows thing ? In this particular case i can simply make sure that the file name is the last argument accumulate all the strings and join them with a space.

Just wondering if this is a true julia issue or i’m doing something silly.

Thanks,

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [January 21, 2019, 8:32pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893/2 "2019-01-21T20:32:03Z")

</div>

turns out a nice way to handle this is to use the following set-up for the argument:

```julia
    arg_type = String
    default = [""]
    nargs = '+'

```

then just do join(args[“argname”], " ") to get the full filename back. However, in the pathological case where there is a ‘-’ after the space it breaks again since ArgParse can only collect strings until it thinks it sees another option.

So

`\\foo\bar\this baz-1.txt`

works, but

`\\foo\bar\this -baz.txt`

does not.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 21, 2019, 8:52pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893/3 "2019-01-21T20:52:32Z")

</div>

```julia
julia argtest.jl -f '\\foo\bar\this baz.txt'

```

is not the same as

```julia
$ . argtest.sh '\\foo\bar\this\ baz.txt'

```

Notice the escaped space in the second version - are you certain that’s not the problem?

---

<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:** [January 21, 2019, 9:38pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893/4 "2019-01-21T21:38:09Z")

</div>

I cannot reproduce this on macOS:

```julia
$ cat tmp/showargs.jl
@show ARGS

```

```julia
$ julia tmp/showargs.jl "foo bar"
ARGS = ["foo bar"]

```

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [January 21, 2019, 9:51pm UTC](https://discourse.julialang.org/t/spaces-in-arguments-when-running-in-cygwin-shell/19893/5 "2019-01-21T21:51:58Z")

</div>

> [@Sukera](#):
>
> Notice the escaped space in the second version - are you certain that’s not the problem?

good catch. i actually ran it both ways, but forgot to paste in the un-escaped version. it’s not the problem though.

```julia
$ . argtest.sh '\\foo\bar\this baz.txt'
"\\foo\bar\this baz.txt"

```

> [@StefanKarpinski](#):
>
> I cannot reproduce this on macOS:

interesting. That made me wonder if this is some weird behavior due to running in a cygwin shell. so i ran it from a windows “cmd” prompt (which i should have thought of originally) and the problem goes away.

So this behavior due to the cygwin shell.

– changed the title since this didn’t have anything to do with ArgParse
