delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/10/27/23:44:05

X-Spam-Check-By: sourceware.org
Date: Fri, 27 Oct 2006 20:43:48 -0700
From: Gary Johnson <garyjohn AT spk DOT agilent DOT com>
To: cygwin AT cygwin DOT com
Subject: Problem passing Windows path names from batch file to bash script
Message-ID: <20061028034348.GA17030@suncomp1.spk.agilent.com>
Mail-Followup-To: cygwin AT cygwin DOT com
MIME-Version: 1.0
User-Agent: Mutt/1.5.12 (2006-07-14)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

I am trying to pass Windows path names from a Windows batch file to 
a Cygwin bash script.  I have found a solution using Windows 
environment variable substitution to replace \s with /s before 
passing the name to bash, but I cannot figure out how to pass the 
name without that replacement.  The problem is with names of the 
form

    "\\host\user\file with spaces"

No matter what I've tried, bash insists on collapsing the two 
leading \s to one, like this,

    \host\user\file with spaces

before anything else can be done with the name.


Here's an illustration of the problem.  I've created a batch file, 
foo.bat, that contains the following lines:

    @echo off
    echo %1 '%1'
    C:\cygwin\bin\bash -c 'echo %1'
    C:\cygwin\bin\bash bar %1 '%1'

and a file, bar, in the same directory containing these lines:

    echo $1 "$1"
    echo $2 "$2"

Executing the following command from the Command Prompt,

    foo "\\host\user\file with spaces"

produces the following output:

    "\\host\user\file with spaces" '"\\host\user\file with spaces"'
    \host\user\file with spaces
    \host\user\file with spaces \host\user\file with spaces
    "\host\user\file with spaces" "\host\user\file with spaces"


I can come up with a number of reasons why I think the results 
should be different, but that doesn't really matter, since there 
must be something I'm missing.  Would someone please explain this 
behavior or direct me to the fine manual I should have read?  How 
should one pass such a path name from Windows to a bash script 
without losing any information?

Thanks,
Gary

-- 
Gary Johnson                 | Agilent Technologies
garyjohn AT spk DOT agilent DOT com     | Wireless Division
                             | Spokane, Washington, USA

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019