OS X terminal: stuck in a ">" line

0

I trying to execute a Curl command (to ElasticSearch REST API) that looks like:

curl -X GET "localhost:9200/_search”?pretty -H 'Content-Type: application/json' -d'
{
  "query": { "match_all": {} }
}
'

I get the angle bracket > on each line, and can't figure out how to execute the command that I've entered from there. I found this page with some info, but I tried the suggestions, and it's not working.

Control + D gives me:

-bash: unexpected EOF while looking for matching `"' -bash: syntax error: unexpected end of file

Writing EOF, then Control + D gives me the same.

BBaysinger

Posted 2018-06-04T18:05:56.693

Reputation: 113

Oh, I'm wrong again. The only problem was the smart quote, which may have been added by a text editor along the way. Agh. – BBaysinger – 2018-06-04T18:28:13.813

FWIW, you should not edit your question to answer the question. That is not how this site works. If you somehow self-solve a question, feel free to post an answer and all is good. – JakeGould – 2018-06-04T18:31:27.853

Answers

2

Your sample is this:

curl -X GET "localhost:9200/_search”?pretty -H 'Content-Type: application/json' -d'
{
  "query": { "match_all": {} }
}
'

That second quote after _search is a “smart quote” (ie: ) instead of a straight quote (ie: "). So it should be; note how I added the quote after ?pretty like this:

curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": { "match_all": {} }
}
'

But that said, it makes little to no sense why there are any quotes around that URL since it can easily work like this:

curl -X GET localhost:9200/_search?pretty -H 'Content-Type: application/json' -d'
{
  "query": { "match_all": {} }
}
'

JakeGould

Posted 2018-06-04T18:05:56.693

Reputation: 38 217

1While the host portion doesn't need to be quoted, the question mark just after it sort of should be (technically it's a wildcard) although it's unlikely to matter. Personally, I'd quote the entire argument (using plain ASCII quotes). – Gordon Davisson – 2018-06-04T19:09:06.390

1

There are some ways to achieve that:

1. Read from stdin

curl -X GET http://localhost:9200/search?pretty -H 'Content-Type: application/json' -d @-

Then you can type the JSON code and press Ctrl+D to send.

You can also pipe it from another program, for instance:

some-node-app-that-outputs-json | curl -X GET http://localhost:9200/search?pretty -H 'Content-Type: application/json' -d @-

2. Read from file

You can also write it to a file and pass the file:

curl -X GET http://localhost:9200/search?pretty -H 'Content-Type: application/json' -d @yourfile.json

Diego S.

Posted 2018-06-04T18:05:56.693

Reputation: 23

2Regarding curl -XGET, actually it's the same as curl -X GET. The -X parameter expects what follows to be the method, so it doesn't matter to curl if GET is separated from parameter or not. – Diego S. – 2018-06-04T18:21:29.560

1

The second "double quote" is wrong. Since the quotes aren't closed, you get $PS2 as a prompt so you can close it.

$ charinfo '"localhost:9200/_search”'
U+0022 QUOTATION MARK [Po]
U+006C LATIN SMALL LETTER L [Ll]
U+006F LATIN SMALL LETTER O [Ll]
 ...
U+0072 LATIN SMALL LETTER R [Ll]
U+0063 LATIN SMALL LETTER C [Ll]
U+0068 LATIN SMALL LETTER H [Ll]
U+201D RIGHT DOUBLE QUOTATION MARK [Pf]

Ignacio Vazquez-Abrams

Posted 2018-06-04T18:05:56.693

Reputation: 100 516