bash -c

Randall R Schulz rrschulz@cris.com
Sun Oct 20 10:50:00 GMT 2002


G,

At 08:37 2002-10-20, g frances wrote:
>Hi,
>I'm new to cygwin and have a simple question.  Tried to find the answer on 
>the mailing list search archive, but no luck.  I've just downloaded the 
>lastest version of Cygwin on Windows 2000 Professional, SP2.  When trying 
>to invoke a command at the NT command prompt like the following:
>
>c:\cygwin\bin\bash -c "cp /testdir/test* /testdir2"
>
>This error occurs--
>cp: testdirtest*: The system cannot find the file specified.

That diagnostic suggests that the command you really entered was this:

c:\cygwin\bin\bash -c "cp \testdir\test* \testdir2"

What you wrote above is (syntactically) correct. What I inferred you 
actually typed is not, since the backslashes are special in a POSIX 
environment and are not that realm's native file separator. Cygwin 
tolerates both Windows and POSIX file name syntaxes (including either 
forward or backward slashes), but that doesn't absolve you from quoting and 
escaping special characters such as backslash to keep them from having 
their special meaning to the Cygwin shell(s).

I recommend you drop the CMD.exe environment and use the power of Cygwin 
and its POSIX / GNU Tools environment alone. You can still invoke 
non-Cygwin programs from Cygwin, you know.

Likewise, you can also directly invoke Cygwin commands from CMD.exe, 
providing you have your local Cygwin bin directory in your Windows PATH. If 
you do that you can invoke Cygwin commands such as "cp" without the 
gyrations of using a shell with the "-c" option. (Be sure it's the Windows 
directory name: "C:\cygwin\bin" you add to the Windows PATH variable.) In 
this case, since BASH was able to execute "cp" without using an absolute 
name, I assume you've already done this.

I'm not completely well-versed on this detail, but I'm under the impression 
that the interpretation of "*" is different when a Cygwin command is 
invoked directly from a Windows CMD.exe. (In a fully Cygwin context, the 
shell itself handles wildcard expansion, but Cygwin programs have special 
startup code that's activated when they're launched from a non-Cygwin 
parent process. That special startup code detects the presence of the 
wild-card character in the arguments and expands them as CMD.exe would).


Chris F.: Please do write that book!


Randall Schulz
Mountain View, CA USA


>But when invoking the same command by just typing within the cygwin shell, 
>it works.
>
>Thanks for your help.
>
>gfrancess


--
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/



More information about the Cygwin mailing list