Reputation:
one case: I wrote script on tsch that invoke other script on python. When I invoke python script from cmd , it is OK. When I invoke test script on tsch then I get error: Argument list too long
Another case:
git grep -e "alex" -- `git ls-files | grep -v 'bin'`
I also get error: Argument list too long
.
What can problem and How to solve it ?
Upvotes: 1
Views: 4197
Reputation: 137
for somebody comes here who need to do something like this:
./shell_script.sh param1
but it raises error Argument list too long
from shell script of param1
.
I just run into this, and fix it by a workaround of using the shell variable.
# calling the PARAM1 instead of $1 in code of shell_script.sh
export PARAM1=param1 ./shell_script.sh
an example of a ruby version of transferring string to nodejs:
ENV["PARAM1"]="a_bunch_of_test_string_as_longer_as_you_can"
`node node_script.sh`
var param1 = process.env.PARAM1;
console.log(param1);
Upvotes: 0
Reputation: 207335
Updated Answer
I'm not familiar with the specific git
commands you are using and you don't seem to be replying sensibly to the questions in the comments either. I guess you probably want something like this though:
git ls-files | grep -v 'bin' | xargs -L 128 git grep -e "alex" --
Original Answer
The classic way to solve "error: Argument list too long" is with xargs
. It can be used to repeatedly call a script whose name you provide, or echo
if you don't provide one, with a limited number of arguments till the arguments are all consumed.
So, imagine you have a million files in a directory, then ls *
will fail, however a simple ls
will work. So, we can put that to use with:
ls | xargs -L 128
which will call echo
(because we didn't provide a utility name) repeatedly with 128 filenames at a time till all are echoed.
So, you could do:
ls | xargs -L 128 yourScript.py
to call your Python script repeatedly with 128 filenames at a time. Of course you may be doing something completely different and incompatible with this technique but your answers are not very helpful so far...
Upvotes: 1