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.
Here you can do (note that that -d
is a GNU extension):
printf '%s\n' {1..12}/01 | xargs -I {} date -d {} +%b | xargs mkdir --
(note that it won't work correctly in locales where month name abbreviations contain spaces or quote characters; with GNU xargs
, you can work around that by using xargs -d '\n' mkdir --
)
Now, to get the list of month abbreviations in your locale, querying the locale directly would make more sense:
(IFS=';'; set -o noglob; mkdir -- $(locale abmon))
(see also locale -k LC_TIME
to see all the locale data in the LC_TIME
category).
Or natively in zsh
:
zmodload zsh/langinfo
mkdir -- ${(v)langinfo[(I)ABMON_*]}
At least on GNU systems, in some locales, month abbreviations are padded to fixed width with spaces:
$ LC_ALL=et_EE.UTF-8 locale title abmon
Estonian locale for Estonia
jaan ;veebr;märts;apr ;mai ;juuni;juuli;aug ;sept ;okt ;nov ;dets
$ LC_ALL=zh_TW.UTF-8 locale title abmon
Chinese locale for Taiwan R.O.C.
1月; 2月; 3月; 4月; 5月; 6月; 7月; 8月; 9月;10月;11月;12月
You may want to remove that padding.
The leading spaces would be removed by xargs -I
, but not the trailing ones. With zsh
:
zmodload zsh/langinfo
set -o extendedglob
mkdir -- ${${${(v)langinfo[(I)ABMON*]}##[[:space:]]#}%%[[:space:]]#}
ls
ed in alphabetical order (Apr, Aug, Dec, Feb, Jan, Jul, Jun, Mar, May, Nov, Oct, Sep). – user1024 Aug 10 '18 at 18:21mkdir january february [...]
? Unless you really need to create them separately there is no need to do it the way you suggested. – Pryftan Aug 10 '18 at 22:17