This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

On 6/26/2015 2:27 PM, wrote:
[ 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.


   targs() {
        if (($# == 0)); then
             _         _
            args=($(cygpath -m -- "$@"))
                   ___           __     __
            IFS=$' \t\n'

        for i in "${args[@]}"; do echo "'$i'"; done

        some_command "${args[@]}"

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.

IMHO you are best served by looking up the stuff in the bash documentation; that's a good way to learn new stuff when exploring example code. Do "man bash", search and enjoy; you can search with REs. But here's some hints.

To handle a list of files, bash arrays are convenient.

1. Why the '(( .... ))' syntax with 'if'? Same as '[ .... ]'?
arithmetic - search for ((: /\(\(
2. Why precede the white space characters with '$'?
that's $'stuff' search: /\$'
3. Why enclose the 'cygpath' command by '($( ... ))'?
that's two things:
$() - search: /\$\(          (but skip past the "$((")
and xxx=() search: /=\(
The "$()" construct replaces the ancient `` syntax, xxx=() is for arrays
4. What does '--' do for 'cygpath'?
The '--' is not cygpath specific. Try man getopt. Note the difference between entering
"cygpath -- -m" and "cygpath -m"
5. Why 'args[@]' rather than just 'args'?
Check this out under "Arrays" in the docs. just "$args" is the first element of the array.
Definitely want @ not *

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


Problem reports:
Unsubscribe info:

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]