3

Usually when you use cURL the output looks like that:

alex$ curl http://some-url
some-content

But, for some urls the outputs is different:

alex$ curl http://some-url
[1] 81030
alex$ some-content
[1]+  Done                    curl http://some-url

Why is that happening and how to get rid of it and make cURL to output just the content?

Alex Craft
  • 11,744
  • 9
  • 55
  • 102

2 Answers2

6

if some-url contains & character then shell interprets it as command to run the process in background.

To overcome it one can escape & with \& (prepend backslash).

John1024
  • 103,964
  • 12
  • 124
  • 155
Kevin
  • 891
  • 1
  • 7
  • 14
6

Kevin's answer is helpful and Kevin deserves credit for inferring your specific problem in the absence of specific information.

Let me complement it with general recommendations:

Rather than individually escaping shell metacharacters (characters with special meaning to the shell) by \-prefixing them, consider:

  • enclosing literals in single quotes; e.g.: curl 'http://example.org/search&query=foo'

  • enclosing variable references in double quotes; e.g.: url='http://example.org/search&query=foo'; curl "$url"

That way you needn't worry about what individual characters to escape.

Generally, only use unquoted literals / variable references if you explicitly want the the shell to interpret them (by applying so-called shell expansions).

Community
  • 1
  • 1
mklement0
  • 312,089
  • 56
  • 508
  • 622