wget script with http get parameters

7.8k views Asked by At

I have a bash script with the following content:

#!/bin/bash
cap=$1
assist=$2
host=$3

wget "http://$host:8080/MyApp/getNumberFromCap?cap=$cap&assist=$assist" -O - -o /dev/null

but when I run this script it does not make any call to the URL indicated. It seems like it's not resolving the variables put in it, in fact, if I replace the variables with a static content it works like a charm.

Where am I doing wrong?

2

There are 2 answers

1
skatz On BEST ANSWER

Escaping the & solved the issue:

wget "http://$host:8080/MyApp/getNumberFromCap?cap=$cap\&assist=$assist" -O - -o /dev/null
                                                       ^
1
user18566012 On

I had to escape the equal sign too:

wget http://${HOST_IP}/my-bin/myscript?MAILADRESSEN\\="${MAILADRESSEN}"\\&SUBJECT\\="${SUBJECT}"