In the documentation for xargs
there is mention of a "replstr" that the -I
flag takes. I started reading about it when I found this command to run fswatch
:
fswatch -0 -e ".*" -i ".rb" . | xargs -0 -n 1 -I {} ruby {}
and started reading the manpage for xargs
-I replstr
Execute utility for each input line, replacing one or more occurrences of replstr in up to replacements (or 5 if no -R flag is
specified) arguments to utility with the entire line of input. The resulting arguments, after replacement is done, will not be
allowed to grow beyond 255 bytes; this is implemented by concatenating as much of the argument containing replstr as possible, to
the constructed arguments to utility, up to 255 bytes. The 255 byte limit does not apply to arguments to utility which do not
contain replstr, and furthermore, no replacement will be done on utility itself. Implies -x.
Thinking about the term "replstr" is seems like it probably means something like "read evaluate print loop string", is this what it's short for? I started playing around with it to try to get an idea for what {}
is doing but I'm not sure I really get it yet:
➜ scripts git:(master) ✗ {0..3}
zsh: command not found: 0..3
➜ scripts git:(master) ✗ echo {0..3}
0 1 2 3
➜ scripts git:(master) ✗ echo {a..3}
a ` _ ^ ] \ [ Z Y X W V U T S R Q P O N M L K J I H G F E D C B A @ ? > = < ; : 9 8 7 6 5 4 3
➜ scripts git:(master) ✗ echo {a..d}
a b c d
➜ scripts git:(master) ✗ echo cats and dogs | xargs
cats and dogs
➜ scripts git:(master) ✗ echo cats and dogs | xargs {}
xargs: {}: No such file or directory
➜ scripts git:(master) ✗ echo cats and dogs | xargs {} echo {}
xargs: {}: No such file or directory
➜ scripts git:(master) ✗ echo cats and dogs | xargs -I {}
➜ scripts git:(master) ✗ echo cats and dogs | xargs -I {} echo {}
cats and dogs
For example echo {a..3}
really doesn't make sense to me. It definitely seems like it's doing something to the effect of "substitute this list of strings here" but I'm not sure if that's the right way to look at it. Also I'm not sure if {}
is a specfic type of replstr and if there's more or if a replstr is just anything in between a pair of curly braces. Would love some guidance on replstr's and how to approach them.