[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Xargs use '\n' as delimiter
From: |
Bob Proulx |
Subject: |
Re: Xargs use '\n' as delimiter |
Date: |
Tue, 30 Dec 2003 11:28:40 -0700 |
User-agent: |
Mutt/1.3.28i |
SuD wrote:
> Hi, if I understood well I must ask here for suggestions on findutils
> package.
This is the wrong list for findutils discussion. Please post your
suggestion to the address@hidden mailing list. It would be
unfair of us to discuss it over here on coreutils which would leave
the current maintainer of the findutils package out of the discussion.
:-)
Thanks
Bob
> 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';
>
>
>
>
> _______________________________________________
> Bug-coreutils mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/bug-coreutils
>