Hacker News new | past | comments | ask | show | jobs | submit login

Wouldn't this fail if your file names have white space?



Parsing `ls` is never a good idea[1]. A more robust way to use globbing in a POSIX shell would be something like this:

    printf "%s\0" files* | xargs -0 -n 1 -P 8 long_process
1. http://mywiki.wooledge.org/ParsingLs


I disagree with the article that you linked. Filenames are variable names that you get to choose. Half of the game is won by chosing them wisely, so that they are convenient to use.


I use this template to deal with reasonable filenames:

    find ... -print0|parallel --gnu -X -0 -n 1 your_command "{}" \;
And sometimes the names are so screwed that they have to be renamed first, then this can give you a reasonable new name

    $(echo $(basename "{}")|tr '[[:blank:]]' '_'| tr -cd '\/.[[:alnum:]]_-' )


yes, and rightfully so. If you don't use silly filenames you can write simpler scripts.


You don't always have the luxury of choosing the names that the files have.


I actually do.

In the rare cases where I have to work with odd filenames, it is easier to rename those files than to change my clean scripts.


Ahh, I see a sysadmin with users! :)


Well, ex-sysadmin for many years now. But yes, real world and all that.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: