I am trying to write a bash script for testing that takes a parameter and sends it through curl to web site. I need to url encode the value to make sure that special characters are processed properly. What is the best way to do this?
Here is my basic script so far:
#!/bin/bash
host=${1:?'bad host'}
value=$2
shift
shift
curl -v -d "param=${value}" http://${host}/somepath $@
Use
curl --data-urlencode; fromman curl:Example usage:
See the man page for more info.
This requires curl 7.18.0 or newer (released January 2008). Use
curl -Vto check which version you have.You can as well encode the query string: