This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

You seem to be over-programming this. If there's a reason, it would help if you explained why you don't simply write 12 lines, "mkdir "Jan"; mkdir "Feb";...". If you need to do it multiple times, put the code in a function, and call as needed.
– jamesqfAug 10 at 17:12

4

Why are you naming your directories with the names of the months instead of the numbers 01-12? It's gotta be awkward having them lsed in alphabetical order (Apr, Aug, Dec, Feb, Jan, Jul, Jun, Mar, May, Nov, Oct, Sep).
– user1024Aug 10 at 18:21

2

@jamesqf Why would you do that when you can simply do mkdir january february [...] ? Unless you really need to create them separately there is no need to do it the way you suggested.
– PryftanAug 10 at 22:17

@user1024 I would normally agree with you but I have for one use case the name of the months (lower case though); in another I have 01january etc. Who can tell? There are numerous reasons it might or might be better one way or another. (But yes - if sorting is an issue...)
– PryftanAug 10 at 22:20

@Pryftan: Only a personal preference for shorter lines :-) Also, if I later wanted to change to e.g. "01Jan", it's easier in my editor to do a "c/ / 01/ 12 1" than to do the change on one line.
– jamesqfAug 11 at 16:44

6 Answers
6

With -I, xargs gets one argument per line as opposed to the default of one argument per (blank or newline delimited, possibly quoted) word without -I (and implies -n). So in your example date is called only once with {} expanded to the whole output of echo (which is on one line), minus the trailing newline.

Your command does not work, because of using -I changes the delimiter of xargs:

-I replace-str
Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character.

You can add -d " " to xargs to make it work. But you don't even need -I{} in your case: