Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.3 content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Subject: RE: dumb escaping question when using Cygwin + NT commands Date: Thu, 19 Sep 2002 12:23:33 -0400 Message-ID: <7BFCE5F1EF28D64198522688F5449D5AC1E227@xchangeserver2.storigen.com> X-MS-Has-Attach: X-MS-TNEF-Correlator: From: "Scott Prive" To: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id g8JGNk214992 Yes that helped; thanks. > -----Original Message----- > From: Igor Pechtchanski [mailto:pechtcha AT cs DOT nyu DOT edu] > Sent: Thursday, September 19, 2002 12:00 PM > To: Scott Prive > Cc: cygwin AT cygwin DOT com > Subject: RE: dumb escaping question when using Cygwin + NT commands > > > On Thu, 19 Sep 2002, Scott Prive wrote: > > > I assumed quotes controlled how data gets sent to commands, but > > apparently that's an oversimplification: quotes protect > data being sent > > to a NEW PROCESS.. and builtins like "echo" are NOT a new > process (`type > > echo). This explains why the echo command understood what > the heck was > > inside '$2', but the echo command did not. > > Not quite. In most shells, the builtin commands are > subjected to the same > quoting rules as the external commands (there are some > exceptions, but I > believe echo isn't one of them). What was happening in your > case was that > on the echo command line, the shell was getting single quotes inside > double quotes, and thus treated them as regular characters > (expanding the > vars within the DOUBLE quotes). When you called your program, on the > other hand, the shell was getting the variables in SINGLE quotes only, > thus avoiding the expansion. > > You should have called both echo and net in the same way: > > net "$1" "$2" "$3" "$4" "$5" > echo "we saw in mount_drive2:" "$1" "$2" "$3" "$4" "$5" > > or, better yet, > > [ $# -eq 5 ] || (echo "Invalid number of arguments" >&2 && exit 2) > net "$@" > echo "we saw in mount_drive2: $@" > > Hope this helps. > Igor > > On Thu, 19 Sep 2002, Scott Prive wrote: > > > > -----Original Message----- > > > From: Randall R Schulz [mailto:rrschulz AT cris DOT com] > > > Sent: Wednesday, September 18, 2002 6:30 PM > > > To: cygwin AT cygwin DOT com > > > Subject: Re: dumb escaping question when using Cygwin + > NT commands > > > > > > > > > Scott, > > > > > > At 15:15 2002-09-18, Scott Prive wrote: > > > > > > >Hello, > > > > > > > >I get this odd problem when calling NT commands from Cygwin. I am > > > >single-quoting the data, but the way I'm doing things > > > (probably wrong...) > > > >does not like passing $1 function arguments to NT commands. > > > If I hardcode > > > >the arguments internally, everything works. > > > > > > > >The two example functions below are intended to behave identical. > > > > > > > >#!/bin sh > > > > > > > >mount_drive () { > > > > # Syntax: net 'use' '*' '\\redhat\foo' 'foo' '/user:foo' > > > > net 'use' 'F:' '\\redhat\foo' 'foo' '/user:foo' > > > > > > > > echo "The command returned $?" > > > > return $?; > > > >} > > > > > > Note that the status ($?) you're returning from the > > > "mount_drive" shell > > > procedure is that of the "echo" command, not that printed > > > _by_ the echo > > > command. > > > > > > The only arguments in this example for which quoting > changes the net > > > argument passed to the underlying command is the one that > > > includes "redhat" > > > and the asterisk. The others contain no special > characters requiring > > > quoting or escaping to inhibit special interpretation. > > > > > > > > > >mount_drive2 () { > > > > net '$1' '$2' '$3' '$4' '$5' > > > > echo "we saw in mount_drive2: '$1' '$2' '$3' '$4' '$5' " > > > > > > > > echo "The command returned $?" > > > > return $?; > > > >} > > > > > > The same "$?" issue exists here, of course. > > > > > > You need to be aware of the difference between 'single > > > quotes' and "double > > > quotes." Variable expansion is inhibited in single-quoted > > > arguments, but > > > not in double-quoted ones. Furthermore, double quoted > > > arguments protect > > > single quotes, making the non-special. So you've probably > > > confused yourself > > > into thinking that in this example the "net" command saw the > > > arguments you > > > passed to the "mount_drive2" procedure. It did not. It saw > > > arguments each > > > consisting of a dollar sign followed by a digit. Then you > > > echoed a single > > > argument composed of some fixed text, some single quote marks > > > and some > > > expanded positional parameters. > > > > Doh! > > > > Thanks. A good nights sleep and coffee got me thinking > about this on the > > way to work, and then I read your post. > > > > I misled myself because the ECHO command "worked". A debugging habit > > from Perl is I would print out my variables. Since the echo > worked, I > > never questioned what I was doing with quotes. > > > > I assumed quotes controlled how data gets sent to commands, but > > apparently that's an oversimplification: quotes protect > data being sent > > to a NEW PROCESS.. and builtins like "echo" are NOT a new > process (`type > > echo). This explains why the echo command understood what > the heck was > > inside '$2', but the echo command did not. > > > > Of course you know this; I'm just filling in the blanks for > the benefit > > of mailing list and Google searches. For all of last night, > I actually > > believed the problem was due to mixing NT commands and Cygwin. > > > > Thanks again. > > > > > > > > > > > ># > > > >mount_drive > > > >mount_drive2 'use' 'G:' '\\redhat\foo' 'foo' '/user:foo' > > > >############# END SCRIPT > > > > > > > > > > > >the output I get from mount_drive2 is standard "usage info", > > > indicating I > > > >passed arguments incorrectly. However the debug echo > *looks* correct. > > > > > > > >Someone please point out my mistake, else I'm doomed to some > > > ugly hackish > > > >workarounds ;-) > > > > > > > >Thanks, > > > > > > > >Scott > > > > > > > > > Randall Schulz > > > Mountain View, CA USA > > > > > > > > > -- > > > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > > > Bug reporting: http://cygwin.com/bugs.html > > > Documentation: http://cygwin.com/docs.html > > > FAQ: http://cygwin.com/faq/ > > > > > > > > > > -- > > Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple > > Bug reporting: http://cygwin.com/bugs.html > > Documentation: http://cygwin.com/docs.html > > FAQ: http://cygwin.com/faq/ > > > > > > -- > http://cs.nyu.edu/~pechtcha/ > |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu > ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com > |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski > '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! > > "Water molecules expand as they grow warmer" (C) Popular > Science, Oct'02, p.51 > > -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/