X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:subject
	:content-type:content-transfer-encoding; q=dns; s=default; b=m/Y
	TwfaV9fCHAQRZvM6TaE9TEkNx2GQq6y1mqaRdXWK/DdOi9vbRpfmvB0bR4lK2abs
	FwtRMxqOcSKXYFyb8UN5dcKxzmZesHAwwSUpGBu82LbGyU+XvFSju/aGLlFEtwr/
	cx7ENQr88E0YwwvqMZ4KeOvRBt7HVqEGqwQbomQg=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:message-id:date:from:mime-version:to:subject
	:content-type:content-transfer-encoding; s=default; bh=fnnhbNxeb
	W4o4Zbdi6EFV0Mz9KI=; b=IkaoW6CrF0Ej41Mooex209myjQlZycLJyf5jZeoaW
	pJQqAl8jjJffuLulkqY3s54UxWXDndTTyCZRf3E14Erc4qsxWep28k3u5/neBtXV
	vcsqMo+MJYFWA32xLHJCuCHuyfgH2uHKgsOGleelH4b2tIS6jXcFvMQzt6t6l7+G
	2w=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2
X-HELO: resqmta-po-05v.sys.comcast.net
Message-ID: <558DD2AF.9050402@raelity.com>
Date: Fri, 26 Jun 2015 15:31:11 -0700
From: Ernie Rael <err@raelity.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: Re: Problem passing file names with embedded space to Windows executable via bash function
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes

On 6/26/2015 2:27 PM, ncokwqc02@sneakemail.com 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.
>>
>>    #!/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.

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.

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


--
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

