public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Randall R Schulz <rrschulz@cris.com>
To: cygwin@cygwin.com
Subject: Re: dumb escaping question when using Cygwin +  NT commands
Date: Wed, 18 Sep 2002 16:17:00 -0000	[thread overview]
Message-ID: <5.1.0.14.2.20020918152313.030eb2e0@pop3.cris.com> (raw)
In-Reply-To: <7BFCE5F1EF28D64198522688F5449D5AC1E21A@xchangeserver2.stor igen.com>

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/

       reply	other threads:[~2002-09-18 22:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7BFCE5F1EF28D64198522688F5449D5AC1E21A@xchangeserver2.stor igen.com>
2002-09-18 16:17 ` Randall R Schulz [this message]
2002-09-19  9:28 Scott Prive
     [not found] <7BFCE5F1EF28D64198522688F5449D5AD63A01@xchangeserver2.stor igen.com>
2002-09-19  9:25 ` Randall R Schulz
  -- strict thread matches above, loose matches on Subject: below --
2002-09-19  9:00 Scott Prive
2002-09-19  9:08 ` Igor Pechtchanski
2002-09-18 15:40 Scott Prive

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.2.20020918152313.030eb2e0@pop3.cris.com \
    --to=rrschulz@cris.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).