My Question is similar to cUrl : Argument list too long

I am sending the following command to CURL from unix shell script

var=$(base64 sample.pdf | perl -pe 's/\n//g')
var1=$(curl -XPUT 'http://localhost:9200/my_index5/my_type/my_id?pipeline=attachment&pretty' -d' { "'"data"'" : "'"$var"'" }')
echo $var1

I got error as curl: /usr/bin/curl: cannot execute [Argument list too long]

Can anyone help to rewrite the above CURL code, to read the 'base64' content from a separate file instead as the argument limit is long ?

2 Answers 2


Issue resolved.

I tried as below,It worked..

var1=$(curl -XPUT 'http://localhost:9200/my_index5/my_type/my_id?pipeline=attachment&pretty' -d @test.json)
echo $var1
  • what's in test.json Commented Apr 9, 2020 at 1:23

On systems with /dev/fd/x, you can also do:

  curl -XPUT 'http://localhost:9200/my_index5/my_type/my_id?pipeline=attachment&pretty' -d @/dev/fd/3 3<< EOF
 { "data" : "$(base64 sample.pdf | tr -d '\n')" }

Depending on the shell implementation, the data is stored in a temporary file or fed via a pipe.

With zsh or bash, you can also do:

  curl -XPUT 'http://localhost:9200/my_index5/my_type/my_id?pipeline=attachment&pretty' \
    -d @<(
      printf ' { "data": "'
      base64 sample.pdf | tr -d '\n'
      printf ' }\n'

Which would be slightly more efficient and also work for commands that output binary data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .