Reputation: 1593
I want to do a curl on git bash without having to type it out. I.e, I want to execute "curl http://google.co.uk
" by running a batchscript in windows.
Is it possible to do this? I am trying this as I am trying to automate several curl requests.
Upvotes: 3
Views: 4242
Reputation: 3646
Great idea to use git bash for testing! If you want to invoke curl several times from a script, I'd use a bash script.
First create a file named doit.sh
, and place your curl commands inside:
#!/bin/env bash
curl http://google.co.uk
curl http://www.google.com
# More as needed...
Save the file and you should be able to run it by double-clicking it in Windows Explorer - or even better, by running it with ./doit.sh
on the command line.
curl is a really powerful tool for this kind of testing, so if you're willing to go down the road of bash scripting you can write more sophisticated tests - for example:
#!/bin/env bash
expected_resp_code="200"
echo "Making sure the response code is '$expected_resp_code'..."
actual_resp_code=$(curl --silent --head --write-out %{http_code} http://www.google.co.uk/ -o /dev/null)
if [[ ! "$actual_resp_code" = "$expected_resp_code" ]] ; then
echo "Expected '$expected_resp_code', but got code '$actual_resp_code'"
exit 1
fi
echo "Success!"
exit 0
Executing your script in git bash might look like:
you@yourmachine ~/Desktop
$ ./doit.sh
Making sure the response code is '200'...
Success!
If you scale up to many dozens or hundreds of tests, you might want to consider moving to another scripting language, but for a few one-off tasks invoking curl from a bash script might serve you well.
Upvotes: 3
Reputation: 1325337
One possible approach: any script called git-xxx.bat
will be executed in a git bash session, even when called (git xxx
) from a cmd DOS session, as long as git-xxx.bat
is in a folder referenced by the %PATH%
.
You could implement your curl
commands in said script.
Upvotes: 0