3

Chrome has given me a curl command that I don't fully recognize. What does the $'{...}' do in the following curl command? I know that the --data-binary is the switch to put that string in the body of the POST, but I'm trying to understand if $'... gets "expanded" or something.

curl 'http://localhost.example.com:8080/graphql' \
-H 'cookie: auth.token_key=zztopTuNQ61YYbHGJpfA00' \
-H 'content-type: application/json' \
--data-binary $'{"query":"query workPlanSearch($searchParameters: WorkPlanSearchParameters\u0021) { workPlanSearch( searchParameters: $searchParameters ) { workPlanId } }","variables":{"searchParameters":{"partNumbers":"000-662-7980-001"}},"operationName":"workPlanSearch"}'

Is it a curl thing or a bash thing?

Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115

2 Answers2

2

I believe this is duplicated of How does the leading dollar sign affect single quotes in Bash?

It causes escape sequences to be interpreted. < This is the accepted answer in the link

And yes, I believe this is a bashism, take a look:

cat sh_test
#!/bin/sh
echo $'{"name":"joao\npedro"}'

./sh_test
${"name":"joao
pedro"}
cat bash_test
#!/bin/bash
echo $'{"name":"joao\npedro"}'

$ ./bash_test
{"name":"joao
pedro"}
lucasgrvarela
  • 351
  • 1
  • 4
  • 9
1

It is used for disambiguation, in your case it means to pass

'{"query":"query workPlanSearch($searchParameters: WorkPlanSearchParameters\u0021) { workPlanSearch( searchParameters: $searchParameters ) { workPlanId } }","variables":{"searchParameters":{"partNumbers":"000-662-7980-001"}},"operationName":"workPlanSearch"}'

as argument

It can used be used for separating a car from text, for example: ${var}text means the content of var and the string text while $vartext means the content of the variable vartext

Itay Brenner
  • 800
  • 6
  • 19