public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* pass arguments enclosed with double quotes from bash shell to windows program
@ 2016-04-02 18:59 Cary Lewis
  2016-04-02 19:34 ` Michael Enright
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Cary Lewis @ 2016-04-02 18:59 UTC (permalink / raw)
  To: cygwin

I need to start acrobat from a bash shell.

Acrobat needs some of its parameters to be enclosed with double
quotes. This is needed to automatically open and print a pdf.

When I try to do that directly from a bash shell, I can't get it to
pass arguments enclosed with the double quotes.

It will do that for arguments with spaces in them, but for single word
arguments, it doesn't

If I try to do a \", then it passes the \" to the windows app.

The only workaround I've come up with so far, is to create a batch
file in the bash shell, and then invoke it with a cmd /c batch.bat

But there should be a way to control how arguments are passed.

Does anyone have any ideas.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pass arguments enclosed with double quotes from bash shell to windows program
  2016-04-02 18:59 pass arguments enclosed with double quotes from bash shell to windows program Cary Lewis
@ 2016-04-02 19:34 ` Michael Enright
  2016-04-02 20:19 ` Eliot Moss
  2016-04-03 11:09 ` Vlado
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Enright @ 2016-04-02 19:34 UTC (permalink / raw)
  To: cygwin

On Sat, Apr 2, 2016 at 11:59 AM, Cary Lewis wrote:
> I need to start acrobat from a bash shell.
>
> Acrobat needs some of its parameters to be enclosed with double
> quotes. This is needed to automatically open and print a pdf.
>
>
> If I try to do a \", then it passes the \" to the windows app.

I frequently use WinMerge, a graphical text file comparision program,
from the bash shell. Occasionally this involves a file in the current
directory vs a file at the end of a path full of spaces and slashes.
If this question had come up yesterday I could have looked at my
history for examples. My recollection is that the rules for expanding
arguments enclosed in single quotes are helpful. Single-quoted
arguments are processed much less by bash than even double-quoted
arguments. A simple example is if you need to put a backslash in an
environment variable, you don't have as many layers to fight if you
use single quotes export regex='search\$'. I also use $(cygpath) in
some fashion to convert the path since WinMerge is not a Cygwin
program. I get the full path to one of the files using tab completion,
and then I modify the path by surrounding it with the necessary
cygpath syntax to convert the path to a Windows path.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pass arguments enclosed with double quotes from bash shell to windows program
  2016-04-02 18:59 pass arguments enclosed with double quotes from bash shell to windows program Cary Lewis
  2016-04-02 19:34 ` Michael Enright
@ 2016-04-02 20:19 ` Eliot Moss
  2016-04-02 23:29   ` René Berber
  2016-04-03 11:09 ` Vlado
  2 siblings, 1 reply; 5+ messages in thread
From: Eliot Moss @ 2016-04-02 20:19 UTC (permalink / raw)
  To: cygwin

On 4/2/2016 2:59 PM, Cary Lewis wrote:
> I need to start acrobat from a bash shell.
>
> Acrobat needs some of its parameters to be enclosed with double
> quotes. This is needed to automatically open and print a pdf.
>
> When I try to do that directly from a bash shell, I can't get it to
> pass arguments enclosed with the double quotes.
>
> It will do that for arguments with spaces in them, but for single word
> arguments, it doesn't
>
> If I try to do a \", then it passes the \" to the windows app.
>
> The only workaround I've come up with so far, is to create a batch
> file in the bash shell, and then invoke it with a cmd /c batch.bat
>
> But there should be a way to control how arguments are passed.
>
> Does anyone have any ideas.

Have you tried:  '"arg"' ? bash should strip the ' ' and leave the " ".
Also, what about "\"foo\"" ?

My experiments with this suggest that they work.  I tried invoked a .bat
file that echoes its first argument, and it did show "\"foo\"", but I
suspect that is how echo renders "foo", i.e., it wraps it in quotes and
backslash protects the quotes.

Here's a function I use for invoking acrobat from the bash command line:

function acrobat () {
   local ARG
   [ -n "$1" ] && { ARG="$(cygpath -wa "$1")"; shift; }
   command acrobat ${ARG:+"${ARG}"} "$@" > /dev/null &
}

For it to work, acrobat needs to be on your path (I put a link in a directory
that is on my path).  Anyway, works fine for me to pop up acrobat displaying
a file.  I've not tired an incantation for printing ...

Best -- Eliot Moss

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pass arguments enclosed with double quotes from bash shell to windows program
  2016-04-02 20:19 ` Eliot Moss
@ 2016-04-02 23:29   ` René Berber
  0 siblings, 0 replies; 5+ messages in thread
From: René Berber @ 2016-04-02 23:29 UTC (permalink / raw)
  To: cygwin

On 4/2/2016 2:19 PM, Eliot Moss wrote:

> Have you tried:  '"arg"' ? bash should strip the ' ' and leave the " ".
> Also, what about "\"foo\"" ?
> 
> My experiments with this suggest that they work.  I tried invoked a .bat
> file that echoes its first argument, and it did show "\"foo\"", but I
> suspect that is how echo renders "foo", i.e., it wraps it in quotes and
> backslash protects the quotes.
> 
> Here's a function I use for invoking acrobat from the bash command line:
> 
> function acrobat () {
>   local ARG
>   [ -n "$1" ] && { ARG="$(cygpath -wa "$1")"; shift; }
>   command acrobat ${ARG:+"${ARG}"} "$@" > /dev/null &
> }
> 
> For it to work, acrobat needs to be on your path (I put a link in a
> directory
> that is on my path).  Anyway, works fine for me to pop up acrobat
> displaying
> a file.  I've not tired an incantation for printing ...

And there's always cygstart, no need to do anything special with the
arguments, if the file has the .pdf extension, it will be opened by the
default application, which usually is Acrobat.

Regards.
-- 
René Berber



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: pass arguments enclosed with double quotes from bash shell to windows program
  2016-04-02 18:59 pass arguments enclosed with double quotes from bash shell to windows program Cary Lewis
  2016-04-02 19:34 ` Michael Enright
  2016-04-02 20:19 ` Eliot Moss
@ 2016-04-03 11:09 ` Vlado
  2 siblings, 0 replies; 5+ messages in thread
From: Vlado @ 2016-04-03 11:09 UTC (permalink / raw)
  To: cygwin

On 2.4.2016 20:59, Cary Lewis wrote:
> I need to start acrobat from a bash shell.
>
> Acrobat needs some of its parameters to be enclosed with double
> quotes. This is needed to automatically open and print a pdf.
>
> When I try to do that directly from a bash shell, I can't get it to
> pass arguments enclosed with the double quotes.
>
> It will do that for arguments with spaces in them, but for single word
> arguments, it doesn't
>
> If I try to do a \", then it passes the \" to the windows app.
>
> The only workaround I've come up with so far, is to create a batch
> file in the bash shell, and then invoke it with a cmd /c batch.bat
>
> But there should be a way to control how arguments are passed.
>
> Does anyone have any ideas.
>
> --
> 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
>
> .
>
Hi Cary Lewis,

maybe this helps:
https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/

Vlado

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-04-03 11:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-02 18:59 pass arguments enclosed with double quotes from bash shell to windows program Cary Lewis
2016-04-02 19:34 ` Michael Enright
2016-04-02 20:19 ` Eliot Moss
2016-04-02 23:29   ` René Berber
2016-04-03 11:09 ` Vlado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).