bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

env (GNU coreutils) 5.93 patch


From: Shigeru Makino
Subject: env (GNU coreutils) 5.93 patch
Date: Sat, 31 Dec 2005 01:06:17 +0900
User-agent: Mozilla Thunderbird 1.0.7 (Windows/20050923)

Hello,

Your “env(1) command is very useful for multi-plat home user.

For example “bash” is in if you don’t know or difference path.

You can write follows script:

#! /usr/bin/env bash

for ((i=0;$i<10;i++))

do

echo $i

done

but I try to same technique for awk script, and get err !

#! /usr/bin/env awk -f

BEGIN {

for (i=0; i < 10; i++) {

print i;

}

}

{

print

}

$ ./test.awk

/usr/bin/env: awk -f: No such file or directory

I make a small path for this error. Please use it if you like this.

-- mac

Index: env.c
===================================================================
RCS file: /var/lib/cvs/mac/src/coreutils-5.93/src/env.c,v
retrieving revision 1.1
retrieving revision 1.5
diff -u -r1.1 -r1.5
--- env.c       30 Dec 2005 07:58:45 -0000      1.1
+++ env.c       30 Dec 2005 15:26:09 -0000      1.5
@@ -79,9 +79,11 @@
 
 #include <config.h>
 #include <stdio.h>
+#include <string.h>
 #include <getopt.h>
 #include <sys/types.h>
 #include <getopt.h>
+#include <ctype.h>
 
 #include "system.h"
 #include "error.h"
@@ -140,6 +142,7 @@
 {
   int optc;
   bool ignore_environment = false;
+  char *argv2[30];
 
   initialize_main (&argc, &argv);
   program_name = argv[0];
@@ -194,11 +197,60 @@
       exit (EXIT_SUCCESS);
     }
 
-  execvp (argv[optind], &argv[optind]);
+
+  char *p;
+  int i;
+  int j;
+
+  for (i = 0; i < 30; i++) {
+         argv2[i] = "";
+  }
+  i = 0;
+  if ((argv2[0] = argv[optind]) != 0) {
+    p = argv2[0];
+    while (*p != 0) {
+      if (isspace(*p)) {
+        *p = 0;
+        while(isspace(*++p) && *p != '\0');
+        if (*p != 0) {
+          if (argv2[i] != NULL && strcmp(argv2[i], "") != 0) {
+           i++;
+          }
+          argv2[i] = p;
+        }
+      }
+      else if (*p == '\'') {
+        *p = 0;
+        if (argv2[i] != NULL && strcmp(argv2[i], "") != 0) {
+          i++;
+        }
+        argv2[i] = p++;
+        while(*++p != '\'' && *p != '\0');
+        *p++ = 0;
+      }
+      else if (*p == '"') {
+        *p = 0;
+        if (argv2[i] != NULL && strcmp(argv2[i], "") != 0) {
+          i++;
+        }
+        argv2[i] = ++p;
+        while(*++p != '"' && *p != '\0');
+        *p++ = 0;
+      }
+      else {
+        ++p;
+      }
+    }
+  }
+  for (j = optind+1; argv[j] != NULL; j++) {
+    argv2[++i] = argv[j];
+  }
+  argv2[++i] = NULL;
+  execvp (argv2[0], &argv2[0]);
 
   {
     int exit_status = (errno == ENOENT ? EXIT_ENOENT : EXIT_CANNOT_INVOKE);
-    error (0, errno, "%s", argv[optind]);
+    error (0, errno, "%s", argv2[0]);
     exit (exit_status);
   }
 }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]