delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2010/02/12/12:33:46

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <202081.90708.qm@web88306.mail.re4.yahoo.com>
X-RocketYMMF: ilatypov
Date: Fri, 12 Feb 2010 09:33:32 -0800 (PST)
From: Ilguiz Latypov <ilatypov AT infradead DOT org>
Subject: execute a file in backslash notation from shell
To: cygwin AT cygwin DOT com
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
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

--0-187882290-1265996012=:90708
Content-Type: text/plain; charset=us-ascii


It never occurred to me that shells are unable to execute their first word in the Windows native backslash format,

  $ 'c:\cygwin\bin\echo.exe' test
  bash: c:\cygwin\bin\echo.exe: command not found

  $ ls -la 'c:\cygwin\bin\echo.exe'     
  -rwxr-xr-x 1 ilatypov Domain Users 48128 2008-12-17 17:16 c:\cygwin\bin\echo.exe


I suspect that none of the shells was ever patched to attempt the "native Windows to
POSIX" conversion on the first word of the command line.  

Ideally, the patches would not be necessary had the shells used a filename translation/detection/manipulation API.  But Posix does not seem to provide a complete API for this.

Alternatively, the shells could attempt to execute the first word as a program through the exec..() family of C library calls.

Instead, bash and pdksh execute the first word of the command line in the following cases.

  (a) The first word has forward slashes.
  (b) Concatenation of the first
word against elements of PATH points (probably, with addition of default suffixes) to an existing file.

I am attaching a patch to pdksh that allows to execute the first word in backslash notation.  This might be necessary for GNU make based build systems that could pass a backslash filename to SHELL as a command.
--0-187882290-1265996012=:90708
Content-Type: text/plain; name="sh.exe-pdksh-5.2.14-3-abs-win-arg0.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="sh.exe-pdksh-5.2.14-3-abs-win-arg0.txt"

LS0tIHNoLmgub3JpZwkyMDEwLTAyLTEyIDAwOjA4OjEzLjE1NDU5MjQwMCAt
MDUwMAorKysgc2guaAkyMDEwLTAyLTEyIDAwOjM2OjI3LjQ3MjgwNDAwMCAt
MDUwMApAQCAtMzM5LDYgKzMzOSwxMiBAQAogIyBkZWZpbmUga3NoX3N0cnJj
aHJfZGlyc2VwKHApICBzdHJyY2hyKHAsIERJUlNFUCkKICNlbmRpZgogCisj
aWZkZWYgX19DWUdXSU5fXworIyBkZWZpbmUgQVJHMF9IQVNfRElSU0VQKHAp
IHN0cnBicmsocCwgIi9cXCIpCisjZWxzZQorIyBkZWZpbmUgQVJHMF9IQVNf
RElSU0VQKHApIGtzaF9zdHJjaHJfZGlyc2VwKHApCisjZW5kaWYKKwogdHlw
ZWRlZiBpbnQgYm9vbF90OwogI2RlZmluZQlGQUxTRQkwCiAjZGVmaW5lCVRS
VUUJMQotLS0gZXhlYy5jLm9yaWcJMTk5OS0wNy0xMyAxMjo1Mzo0Ni4wMDAw
MDAwMDAgLTA0MDAKKysrIGV4ZWMuYwkyMDEwLTAyLTEyIDAwOjM4OjA1Ljgw
OTYzMDYwMCAtMDUwMApAQCAtNTY5LDcgKzU2OSw3IEBACiAJCXJ2ID0gc3Vi
c3RfZXhzdGF0OwogCQlnb3RvIExlYXZlOwogCX0gZWxzZSBpZiAoIXRwKSB7
Ci0JCWlmIChGbGFnKEZSRVNUUklDVEVEKSAmJiBrc2hfc3RyY2hyX2RpcnNl
cChjcCkpIHsKKwkJaWYgKEZsYWcoRlJFU1RSSUNURUQpICYmIEFSRzBfSEFT
X0RJUlNFUChjcCkpIHsKIAkJCXdhcm5pbmdmKFRSVUUsICIlczogcmVzdHJp
Y3RlZCIsIGNwKTsKIAkJCXJ2ID0gMTsKIAkJCWdvdG8gTGVhdmU7CkBAIC05
ODUsNyArOTg1LDcgQEAKIAljaGFyICpmcGF0aDsJCQkvKiBmb3IgZnVuY3Rp
b24gYXV0b2xvYWRpbmcgKi8KIAljaGFyICpucGF0aDsKIAotCWlmIChrc2hf
c3RyY2hyX2RpcnNlcChuYW1lKSAhPSBOVUxMKSB7CisJaWYgKEFSRzBfSEFT
X0RJUlNFUChuYW1lKSAhPSBOVUxMKSB7CiAJCWluc2VydCA9IDA7CiAJCS8q
IHByZXZlbnQgRlBBVEggc2VhcmNoIGJlbG93ICovCiAJCWZsYWdzICY9IH5G
Q19GVU5DOwpAQCAtMTIyMCw3ICsxMjIwLDcgQEAKIAlpZiAoc2VhcmNoX2Fj
Y2VzcyhYc3RyaW5nKHhzLCB4cCksIG1vZGUsIGVycm5vcCkgPT0gMCkgCiAJ
CXJldHVybiBYc3RyaW5nKHhzLCB4cCk7IC8qIG5vdCBYY2xvc2UoKSAtIHhw
IG1heSBiZSB3cm9uZyAqLwogI2Vsc2UgLyogT1MyICovCi0JaWYgKGtzaF9z
dHJjaHJfZGlyc2VwKG5hbWUpKSB7CisJaWYgKEFSRzBfSEFTX0RJUlNFUChu
YW1lKSkgewogCQlpZiAoc2VhcmNoX2FjY2VzcyhuYW1lLCBtb2RlLCBlcnJu
b3ApID09IDApCiAJCQlyZXR1cm4gKGNoYXIgKikgbmFtZTsKIAkJcmV0dXJu
IE5VTEw7Cg==


--0-187882290-1265996012=:90708
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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