Linux has a limit of 128 kB for the length of a single argument string, but that's a lot longer a limit than the string you tried. As far as I understand, most other systems have no specific limit for the length of a single argument, but of course have some limits for their total length (it'll have to be limited by available memory anyway, possibly stack space in particular). If Bash itself has a limit, it's likely long enough for all practical purposes.
Se e.g. this should work:
% bash -c "echo $(printf "1234567890%.0s" {0..30}) | rev"
0987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321
The fact that your command leaves some of the %
s unexpanded and that it depends on the resulting length, hints at that being an issue of that xargs
implementation. (Is it the GNU one? I'm slightly surprised if they have such a low limit.)
In any case, as mentioned in the comments, it's not such a good idea to embed data directly into your shell script as here. It can lead to issues with strange inputs (think quotes), and those can escalate into security problems. Best to avoid doing it.
Instead, pass the data string as an argument to Bash, where it will be available as $1
in the script (the following args being $2
, $3
etc).
echo '123456789#' | xargs -I{} bash -c 'echo "$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1"' bash {}
(Note that you still can't pass strings with quotes or backslashes (or that start with whitespace) into that without further consideration, since xargs
itself does some quote processing on the input unless you use non-standard options such as the -0
/ -d
of GNU xargs
.)
ARG_MAX
setting so you may have something else going on. What happens if you useecho 'x' | xargs ...
instead? Do you get 25x
s or not? From testing with other input strings, is the output truncated at 240 chars or 24 repetitions of the input or something else? Or do you see a literal%
at the end of the output?%
in the shell code in the first place.echo '123456789#' | xargs -I% bash -c 'echo "$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1"' bash %
x
xargs
shall follow this: "At least five arguments in arguments can each contain one or more instances of replstr. Each of these constructed arguments cannot grow larger than an implementation-defined limit greater than or equal to 255 bytes". So maybe it's yourxargs
that is limited; which is another reason to use the code from my first comment where%
gets expanded exactly once and the resulting string is short; then the long string to echo is built inbash
, not byxargs
.