[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Xargs use '\n' as delimiter
From: |
SuD |
Subject: |
Xargs use '\n' as delimiter |
Date: |
Tue, 30 Dec 2003 16:43:02 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; es-ES; rv:1.1) Gecko/20020826 |
Hi, if I understood well I must ask here for suggestions on findutils
package.
I would like to discuss (again?) the use of character '\n' as an
argument delimiter for xargs. In certain cases it can be useful to allow
xargs to split arguments using \n. For example, most times a "ls | xargs
..." would work fine using each line as a file. I know that it wont work
with filenames that contain '\n', but i think it is worth for many users
many times (unless someone implements ls compatible with xargs -0 :).
I suggest a mode switch that allows splitting arguments using '\n', and
treating '\"', '\'', and others as normal characters. That is equivalent
as -0 switch, but substituting '\0' by '\n' (as someone stated before).
Actually, this script does what i have said, and what the patch below does:
awk 'BEGIN{ORS="\0"} {print}'
The switches could be extended to selectively switch on and off things
like: the use of escape characters like '\"', allow any specified
character to act as delimiter, etc (all these ideas are not included in
the patch below).
A note on documentation. Should be said that arguments starting with '-'
character may cause some trouble? If i do "ls | xargs ls" and there
exists a file named "-w" i should call xargs like this: "ls | xargs ls
--" or i'd get an error on ls (s: option requires an argument -- w).
The patch. Apply patch on findutils/. It is not intended to be
definitive, it adds a -N switch that allows the use of '\n' instead of
'\0'.
Thank you for reading ;)
--- xargs.orig/xargs.c 2003-12-28 17:51:41.000000000 +0100
+++ xargs/xargs.c 2003-12-28 17:49:04.000000000 +0100
@@ -265,6 +265,9 @@
execute the command if the user responds affirmatively. */
static boolean query_before_executing = false;
+/* The argument delimiter for -0 and -N options */
+static char delimiter = '\0';
+
static struct option const longopts[] =
{
{"null", no_argument, NULL, '0'},
@@ -331,7 +334,7 @@
if (arg_max <= 0)
error (1, 0, _("environment is too large for exec"));
- while ((optc = getopt_long (argc, argv, "+0e::i::l::n:prs:txP:",
+ while ((optc = getopt_long (argc, argv, "+0e::i::l::n:prs:txNP:",
longopts, (int *) 0)) != -1)
{
switch (optc)
@@ -398,6 +401,11 @@
always_run_command = 0;
break;
+ case 'N':
+ read_args = read_string;
+ delimiter = '\n';
+ break;
+
case 'P':
proc_max = parse_num (optarg, 'P', 0L, -1L);
break;
@@ -626,7 +634,7 @@
push_arg (linebuf, len);
return len;
}
- if (c == '\0')
+ if (c == delimiter)
{
lineno++; /* For -l. */
*p++ = '\0';
- Xargs use '\n' as delimiter,
SuD <=