Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com> List-Archive: <http://sources.redhat.com/ml/cygwin/> List-Post: <mailto:cygwin AT cygwin DOT com> List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-Id: <5.1.0.14.2.20020918152313.030eb2e0@pop3.cris.com> X-Sender: rrschulz AT pop3 DOT cris DOT com Date: Wed, 18 Sep 2002 15:30:24 -0700 To: cygwin AT cygwin DOT com From: Randall R Schulz <rrschulz AT cris DOT com> Subject: Re: dumb escaping question when using Cygwin + NT commands In-Reply-To: <7BFCE5F1EF28D64198522688F5449D5AC1E21A@xchangeserver2.stor igen.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed 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. ># >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/