Bash and curl, getting custom argument working

I'm trying to make a very small script but i run into a problem, i want to call a simple bash script, passing an IP addres, like this:

./bashScript 192.111.211.211

the script looks like this:

#!/bin/bash
curl https://www.xxx.com/api_json.html \
  -d 'a=ban' \
  -d 'tkn=xxxxxx' \
  -d 'email=xxx@gmail.com' \
  -d 'key=$1' \

but it isn't working, the $1 argument is not sending and i get an error from the web-service.

What i'm doing wrong?

Thanks a lot!

Upvotes: 1

Views: 295

Answers (1)

Fred Foo
Fred Foo

Reputation: 363817

Use doubles quotes:

-d "key=$1"

Single quotes prevent variable expansion:

~$ foo=bar
~$ echo '$foo'
$foo
~$ echo "$foo"
bar

Upvotes: 3

Related Questions