Skip to main content
edited body
Source Link
cas
  • 84.2k
  • 9
  • 136
  • 205

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl. IN In other words, it's the same as running:

curl -X POST "-d 'tag=jazz' -d 'language=english' -d 'state=queensland'" "$SEARCH_URL"

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as if it were a separate quoted string - which is especially useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl. IN other words, it's the same as running:

curl -X POST "-d 'tag=jazz' -d 'language=english' -d 'state=queensland'" "$SEARCH_URL"

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as if it were a separate quoted string - which is especially useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl. In other words, it's the same as running:

curl -X POST "-d 'tag=jazz' -d 'language=english' -d 'state=queensland'" "$SEARCH_URL"

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as if it were a separate quoted string - which is especially useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'
added 148 characters in body
Source Link
cas
  • 84.2k
  • 9
  • 136
  • 205

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl. IN other words, it's the same as running:

curl -X POST "-d 'tag=jazz' -d 'language=english' -d 'state=queensland'" "$SEARCH_URL"

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as if it were a separate quoted string - which is especially useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl.

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as a separate quoted string - which is useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl. IN other words, it's the same as running:

curl -X POST "-d 'tag=jazz' -d 'language=english' -d 'state=queensland'" "$SEARCH_URL"

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as if it were a separate quoted string - which is especially useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'
Source Link
cas
  • 84.2k
  • 9
  • 136
  • 205

The double-quotes around "$OPTS" prevents the contents of the variable from being split on white-space, so it's treated as one argument to curl.

Use an array instead. For example:

SEARCH_URL="http://91.132.145.114/json/stations/search"

OPTS=(-d 'tag=jazz' -d 'language=english' -d 'state=queensland')
curl -X POST "${OPTS[@]}" "$SEARCH_URL"

That will cause each element of the OPTS array to be interpolated into the curl command line as a separate quoted string - which is useful if the element contains, e.g., whitespace characters.

BTW, when parsing your options, you can add new elements to an array like:

OPTS+=(newoption)

or

OPTS+=(-d 'foo=bar')    # add two new elements: '-d' and 'foo=bar'