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
  • 13,598
  • 11
  • 69
  • 133

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
  • 109,961
  • 14
  • 137
  • 171
Kevin
  • 901
  • 1
  • 7
  • 15
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
  • 382,024
  • 64
  • 607
  • 775