Spaces in arguments when running in cygwin shell?

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

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:

#!/bin/bash

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

I get the expected result

$ . 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,

1 Like

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

    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.

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

is not the same as

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

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

I cannot reproduce this on macOS:

$ cat tmp/showargs.jl
@show ARGS
$ julia tmp/showargs.jl "foo bar"
ARGS = ["foo bar"]

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

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

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