[prev] [thread] [next] [lurker] [Date index for 2004/03/04]
> and so forth. Oh yes I know there are ways to get around this. But > 'find' knows it has a filename there which has a space in it and 'xargs' > is designed to work with 'find' so why can't they just sort themselves > out and deal with these as filenames rather than a bunch of space > delimited tokens. Because xargs has been defined to take whitespace-delimited filenames for so long that there's almost certainly someone somewhere who's got code that depends on it. Plus, it's religious. find -print0 and xargs -0 is safe, whereas fixing xargs is "merely convenient". Unless you're trying to do more than find can handle and you want to filter the output, then you discover that things like "grep" don't like nulls. If not for the religious "if we allow you to do unsafe things, you will do unsafe things" they'd define two options (eg: --newline and --whitespace) in xargs and say "until 2005/12/31 the default will be --whitespace, after that it will be --newline". So, with no further ado, try: find ... | filters | tr '\n' '\000' | xargs -0 ... If you have a "tr" that has problems with nulls, use this instead: #include <stdio.h> void nullify(FILE *, char *); void usage(void); char *prog; main(int ac, char **av) { FILE *fp = NULL; prog = strrchr(*av, '/'); if(!prog) prog = *av; while(*++av) { fp = fopen(*av, "r"); if(!fp) { perror(*av); usage(); exit(1); } nullify(fp, *av); fclose(fp); } if(!fp) nullify(stdin, NULL); exit(0); } void usage(void) { fprintf(stderr, "Usage: %s [file]...\n", prog); } void nullify(FILE *fp, char *name) { int c; while(-1 != (c = getc(fp))) { if(c=='\n') c = 0; putchar(c); } }
Generated at 14:02 on 01 Jul 2004 by mariachi 0.52