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.
--- sh.h.orig 2010-02-12 00:08:13.154592400 -0500
+++ sh.h 2010-02-12 00:36:27.472804000 -0500
@@ -339,6 +339,12 @@
# define ksh_strrchr_dirsep(p) strrchr(p, DIRSEP)
#endif
+#ifdef __CYGWIN__
+# define ARG0_HAS_DIRSEP(p) strpbrk(p, "/\\")
+#else
+# define ARG0_HAS_DIRSEP(p) ksh_strchr_dirsep(p)
+#endif
+
typedef int bool_t;
#define FALSE 0
#define TRUE 1
--- exec.c.orig 1999-07-13 12:53:46.000000000 -0400
+++ exec.c 2010-02-12 00:38:05.809630600 -0500
@@ -569,7 +569,7 @@
rv = subst_exstat;
goto Leave;
} else if (!tp) {
- if (Flag(FRESTRICTED) && ksh_strchr_dirsep(cp)) {
+ if (Flag(FRESTRICTED) && ARG0_HAS_DIRSEP(cp)) {
warningf(TRUE, "%s: restricted", cp);
rv = 1;
goto Leave;
@@ -985,7 +985,7 @@
char *fpath; /* for function autoloading */
char *npath;
- if (ksh_strchr_dirsep(name) != NULL) {
+ if (ARG0_HAS_DIRSEP(name) != NULL) {
insert = 0;
/* prevent FPATH search below */
flags &= ~FC_FUNC;
@@ -1220,7 +1220,7 @@
if (search_access(Xstring(xs, xp), mode, errnop) == 0)
return Xstring(xs, xp); /* not Xclose() - xp may be wrong */
#else /* OS2 */
- if (ksh_strchr_dirsep(name)) {
+ if (ARG0_HAS_DIRSEP(name)) {
if (search_access(name, mode, errnop) == 0)
return (char *) name;
return NULL;
--
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