Problem passing file names with embedded space to Windows executable via bash function

ncokwqc02@sneakemail.com ncokwqc02@sneakemail.com
Fri Jun 26 21:28:00 GMT 2015


[ This is meant to be a reply to the response post by Ernie Rael, which I managed to lose so there is no referencing. ]

On 6/26/2015 12:50 PM, Ernie Rael wrote:

>I use something similar to this, perhaps it would meet your needs. You may want to use >different option to cygpath.
>
>   #!/usr/bin/bash
>
>   targs() {
>        if (($# == 0)); then
            _         _
>            args=()
>        else
>            IFS=$'\n'
                 _
>            args=($(cygpath -m -- "$@"))
                  ___           __     __
>            IFS=$' \t\n'
                 _
>        fi
>
>        for i in "${args[@]}"; do echo "'$i'"; done
>
>        some_command "${args[@]}"
                             ___
>   }
>
>
>-ernie

I modified Ernie's solution for my purposes and it works beautifully. Thanks so much.

The key point seems to be the temporary redefinition of IFS.

However, Ernie's solution also incorporates other features / syntactical elements of bash that I would never have thought to use and I'm interested to know if they are necessary and what they do. They are underlined in the message above. 

Basically,
1. Why the '(( .... ))' syntax with 'if'? Same as '[ .... ]'?
2. Why precede the white space characters with '$'?
3. Why enclose the 'cygpath' command by '($( ... ))'?
4. What does '--' do for 'cygpath'?
5. Why 'args[@]' rather than just 'args'?

Anyway, thanks for the simple solution to my problem. If I learn some more about obscure bash syntax that will be a bonus.

jjo


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list