-2

I got error "Argument list too long" when I pass a very long text as an argument to a script. For example:

./myScript.bash "${v_very_long_text}"

Is that a way to fix the error? thanks

Barmar
  • 741,623
  • 53
  • 500
  • 612
Ngea
  • 17
  • 1
  • 4
    rewrite your script to consume stdin – jhnc Mar 04 '19 at 17:29
  • 1
    Probably you have to change the way how to pass the data to your script. Show the code of your script and sample contents of `v_very_long_text` to get suggestions. – Bodo Mar 04 '19 at 17:30
  • Or rewrite the script to read from a file, and make the filename the argument. – Paul Hodges Mar 04 '19 at 17:32
  • Reading from stdin would allow putting the string in a here-doc – Barmar Mar 04 '19 at 17:51
  • Possible duplicate of [Argument list too long error for rm, cp, mv commands](https://stackoverflow.com/q/11289551/608639) – jww Mar 05 '19 at 01:12

1 Answers1

-2

Method 1:

echo "${v_very_long_text}" > text_file.txt
./myScript.bash $(cat text_file.txt)

Method 2:

tee text_file.txt <<EOF
line 1
line 2
line 3
EOF

./myScript.bash $(cat text_file.txt)