From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30194 invoked by alias); 18 Sep 2002 22:30:21 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 30187 invoked from network); 18 Sep 2002 22:30:19 -0000 Received: from unknown (HELO uhura.concentric.net) (206.173.118.93) by sources.redhat.com with SMTP; 18 Sep 2002 22:30:19 -0000 Received: from marconi.concentric.net (marconi.concentric.net [206.173.118.71]) by uhura.concentric.net [Concentric SMTP Routing 1.0] id g8IMUFc14466 for ; Wed, 18 Sep 2002 18:30:15 -0400 (EDT) Received: from Clemens.cris.com (da003d1040.sjc-ca.osd.concentric.net [64.1.4.17]) by marconi.concentric.net (8.9.1a) id SAA25644; Wed, 18 Sep 2002 18:30:13 -0400 (EDT) Message-Id: <5.1.0.14.2.20020918152313.030eb2e0@pop3.cris.com> X-Sender: rrschulz@pop3.cris.com Date: Wed, 18 Sep 2002 16:17:00 -0000 To: cygwin@cygwin.com From: Randall R Schulz 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 X-SW-Source: 2002-09/txt/msg00919.txt.bz2 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/