diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | xe.c | 5 |
2 files changed, 7 insertions, 1 deletions
diff --git a/README.md b/README.md index 631d590..ad1aea6 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,9 @@ Over apply: If no argument is passed, default to "printf %s\n". +The current iteration is passed as `$ITER` to the child process +(increased on every exec()). + ## Return code Like GNU and OpenBSD xargs: diff --git a/xe.c b/xe.c index f9c7206..a17f1a4 100644 --- a/xe.c +++ b/xe.c @@ -30,7 +30,7 @@ static int maxatonce = 1; static int maxjobs = 1; static int runjobs = 0; static int Rflag, aflag, kflag, nflag, vflag; -static int iterations = 0; +static long iterations = 0; static char * xstrdup(const char *s) @@ -155,6 +155,9 @@ run(char *cmd[]) pid = fork(); if (pid == 0) { // in child + char iter[32]; + snprintf(iter, sizeof iter, "%ld", iterations); + setenv("ITER", iter, 1); // redirect stdin to /dev/null int fd = open("/dev/null", O_RDONLY); if (fd >= 0) { |