Usage of the percentile operator in shell scripts

0

In this link: https://superuser.com/a/180252/401901

The following command is used:

cat list.txt | xargs -I % echo cp % new_folder

What does the % % usage mean?

All google search results are about using it in a modulo operation. Or, am I searching it in a wrong way?

Also, is there a name for this kind of usage?

Thank you!

sravi

Posted 2018-10-11T22:53:57.763

Reputation: 1

Answers

1

From man 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;  in‐
          stead the separator is the newline character.  Implies -x and -L 1.

So it sets up % to be the part of the command which is replaced by the list of files.

l0b0

Posted 2018-10-11T22:53:57.763

Reputation: 6 306

Yep. This %-sign isn't some kind of shell operator, it's just being used by xargs as a placeholder string so xargs knows where to insert the strings that are being piped in via stdin. When I use xargs, I usually use "HERE" as my string for -I or -J, which makes it more clear that it's just a string to tell xargs to "insert the input right HERE in this command line". – Spiff – 2018-10-12T01:04:59.590