Kurt
Kurt

Reputation: 21

"Argument list too long" in display all list elements

I would like to dump the content in a list, but I have no idea how to solve this problem now.

When I try to display all elements in the list, shell shows:

arguments list too long

in Makefile:

$(FILE_SOURCE:%= echo % >> $(FILE_LIST_TMP);)

Message:

execvp: /bin/sh: Argument list too long

Is there any other way to solve this problem without recompiling the kernel?

I would appreciate any suggestions. Thanks

Now I use perl to solve the problem. The following is my method:

while read line; do
  perl -e 'print "$$ARGV[0]\n"' $$line >> $(FILE_LIST_TMP) ; \
done < $(FILE_SOURCE)`

Upvotes: 2

Views: 5752

Answers (1)

MadScientist
MadScientist

Reputation: 100926

One way you can make the command line much shorter is to not use $(FILE_LIST_TMP) in every single echo. Instead, just use it once, like this:

(${FILE_SOURCE:%=echo %;}) > $(FILE_LIST_TMP)

Now instead of sending this to the shell:

echo foo >> my_temp_file ; echo bar >> my_temp_file ; echo baz >> my_temp_file; ..

you'll use this:

(echo foo; echo bar; echo baz;) > my_temp_file

which will be significantly shorter, especially as the number of files gets larger and especially if your temporary file name is long-ish.

Another trick you can play, if the files in FILE_SOURCE are all in a subdirectory that has a common path, is to cd there then you can omit that path from the echo lines.

However, even this may eventually not be sufficient if the list is long enough.

Upvotes: 2

Related Questions