Mail Archives: cygwin/2002/09/18/18:30:28
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/
- Raw text -