How to pass a variable in a curl command in shell scripting How to pass a variable in a curl command in shell scripting shell shell

How to pass a variable in a curl command in shell scripting


When using variables in , you can only use doubles quotes, not single quotes : the variables inside single quotes are not expanded.Learn the difference between ' and " and `. See http://mywiki.wooledge.org/Quotes and http://wiki.bash-hackers.org/syntax/words


I ran into this problem with passing as well, it was solved by using ' " $1 " '

See connection.uri below

curl -X POST -H "Content-Type: application/json" --data '  {"name": "mysql-atlas-sink",   "config": {     "connector.class":"com.mongodb.kafka.connect.MongoSinkConnector",     "tasks.max":"1",     "topics":"mysqlstock.Stocks.StockData",     "connection.uri":"'"$1"'",     "database":"Stocks",     "collection":"StockData",     "key.converter":"io.confluent.connect.avro.AvroConverter",     "key.converter.schema.registry.url":"http://schema-registry:8081",     "value.converter":"io.confluent.connect.avro.AvroConverter",     "value.converter.schema.registry.url":"http://schema-registry:8081",     "transforms": "ExtractField",     "transforms.ExtractField.type":"org.apache.kafka.connect.transforms.ExtractField$Value",     "transforms.ExtractField.field":"after"}}' http://localhost:8083/connectors -w "\n"


userdetails="$username:$apppassword"base_url_part='https://api.XXX.org/2.0/repositories'path="/$teamName/$repoName/downloads/$filename"base_url="$base_url_part$path"**strong text**curl  -L -u "$userdetails" "$base_url" -o "$downloadfilename"