How to append a variable to CURL command - linux

I am trying to use curl qrenco.de/google.com with an alias so that the alias takes the input parameter google.com and appends it to curl qrenco.de/. i want it to look something like this:
$qrcode google.com
i have tried the following:
alias qrcode='curl qrenco.de/$(read)'
but this doesn't seem to work. i am new to bash and would like to know the right approach.

Almost every time an alias gives you trouble, you should just be using a function.
qrcode() { curl qrenco.de/"$1"; }

Related

Use alias and add variable together

I found nice command to check whether in terminal:
curl wttr.in/
By adding after slash city name it will show whether in typed place for example:
curl wttr.in/NewYork
There is need to simplify this command using alias but then it appear a problem with variable after alias.
alias yyy="curl wttr.in/"
There is error trying to use alias with variable in terminal:
yyy NewYork
How manage to use alias with variable?
You can create a function and use it the same way you use an alias
function yyy() { curl wttr.in/${1}; }
yyy NewYork

how to pass float value as query params using curl?

I have a python flask server running and the following http GET works on my browser, http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741 , however when I use command curl http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741 it doesn't work. How to correct my query to work for curl?
You have to pass URL as a string.
It's because for shell a lot of characters used in URL have special meaning (ie = is an assignment, & makes command to run in background, etc). So
curl "http://example.com/v1/api?lng=18.565810740668912&lat=-33.93153605161741"
should work as expected.
To pass the query-parameters separated and let cURL build the query-string we can also use option -G together with usual -d like
curl -G -d 'lng=18.565810740668912' -d 'lat=-33.93153605161741' http://example.com/v1/api
See also: Construct a Query String (TLDR: Use -G argument)

zsh: no matches found when $ curl -s -X localhost:60702/api/bundle?name=light%20reading | j q '.'

I am working through the Node.js The Right Way book by Jim Wilson. I am currently trying to use a PUSH request to create a new bundle with the specified name.
* curl -X POST http://:/api/bundle?name=
However, when I use the command:
$ curl -s -X POST localhost:60702/api/bundle?name=light%20reading | jq '.'
rather than getting the JSON indicating that a Bundle has been created, I get: zsh: no matches found: localhost:60702/api/bundle?name=light%20reading
The command should be using a POST request to create a new All of my code is bit for bit identical to the code listed in the book. Any ideas?
Can you try
curl -s -X POST 'localhost:3000/api/bundle?name=light%20reading'
i.e wrap the url within '
This seems to be an issue with zsh solved here.
There are several ways to solve this:
You can escape the question mark ? in the url by quoting the url as explained by #huzaifa-saifuddin to avoid zsh treating it as a wildcard character.
As explained here, you can create an alias for curl: alias curl='noglob curl'
As explained here, you can disable to nomatch handling by adding the following to your ~/.zshrc: unsetopt nomatch

Linux-wget command

I need a quick help on customizing my wget command in a shell script:
The wget command looks something like this:
wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa. products.ldm.ingestion.server.scala/10.0.0.135.527-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-10.0.0.135.527-20150622.210643-1-sources.jar
Here I'd like to add the 10.0.0.135.527 in a variable, so I created a script something like this:
n = 10.0.0.135.527
wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa.products.ldm.ingestion.server.scala/"$n"-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-"$n"-20150622.210643-1-sources.jar
but this is not working, any idea what's wrong here?
Try this to create a string variable n, with no leading whitespace (thanks #011c):
n="10.0.0.135.527"
wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa.products.ldm.ingestion.server.scala/"$n"-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-"$n"-20150622.210643-1-sources.jar

Usage of Wget for a long URL

I am trying to download a file with the below URL:
wget http://example.com/reports/downloadreport?roleId=8&loginName=9011613&code=123
But it takes only till
http://example.com/reports/downloadreport?roleId=8
not sending the remaining things. I need to send at least role ID and loginName to get the file.
I tried to create a shell script like below, but that is not working either:
i="http://euroams.eurekaforbes.co.in:8080/efms/reports/bamsinvoiceresultdownload?roleId=8&loginName=9011613"
wget --tries=45 -i $i
How can I fix this?
Enclose the URL in quotes. Your shell is interpreting the "&" rather than passing it as a parameter, so it's seeing what you typed as the following (three commands rather than one):
wget http://example.com/reports/downloadreport?roleId=8 &
loginName=9011613 &
code=123

Resources