The curl command is not executed through a shell script in bash

I study shell scripts! for the same thing, I tried to load the facebook page using curl on the ubuntu terminal.

t.sh

vi@vi-Dell-7537 (Desktop) $ cat t.sh curlCmd="curl \"https://www.facebook.com/vivekkumar27june88\"" echo $curlCmd ($curlCmd) > ~/Desktop/fb.html 

Error starting script like

 vi@vi-Dell-7537 (Desktop) $ ./t.sh curl "https://www.facebook.com/vivekkumar27june88" curl: (1) Protocol "https not supported or disabled in libcurl 

But if you run the command directly, then it works fine.

 vi@vi-Dell-7537 (Desktop) $ curl "https://www.facebook.com/vivekkumar27june88" <!DOCTYPE html> <html lang="hi" id="facebook" class="no_js"> <head><meta chars..... 

I would be grateful if someone would tell me the error that I am making in the script.

I checked that the curl library has ssl.

+4
source share
4 answers

Bracket Inline Command , works as a sub-shell , so your environment variables will be absent.

Try eval:

 curlCmd="curl 'https://www.facebook.com/vivekkumar27june88' > ~/Desktop/fb.html" eval $curlCmd 
+10
source

Create the t.sh script only on this single line:

 curl -k "https://www.facebook.com/vivekkumar27june88" -o ~/Desktop/fb.html 

According to man curl :

-k, --insecure

 (SSL) This option explicitly allows curl to perform "insecure" SSL connections transfers. All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default. This makes all connections considered "insecure" fail unless -k, --insecure is used. 

-o file

 Store output in the given filename. 
+3
source

As @ Chepner said, go ahead and read BashFAQ # 50: I'm trying to add a command to a variable, but complex cases always fail! . To summarize how you should do such things, depends on your goal.

  • If you do not need to save the team, do not do this! Saving commands is hard to get right, so if you don't need to, just skip this clutter and do it directly:

     curl "https://www.facebook.com/vivekkumar27june88" > ~/Desktop/fb.html 
  • If you want to hide the details of the command or intend to use it a lot and do not want to write it out every time, use the function:

     curlCmd() { curl "https://www.facebook.com/vivekkumar27june88" } curlCmd > ~/Desktop/fb.html 
  • If you need to assemble the command individually, use an array instead of a simple string variable:

     curlCmd=(curl "https://www.facebook.com/vivekkumar27june88") for header in "${extraHeaders[@]}"; do curlCmd+=(-H "$header") # Add header options to the command done if [[ "$useSilentMode" = true ]]; then curlCmd+=(-s) fi "${curlCmd[@]}" > ~/Desktop/fb.html # This is the standard idiom to expand an array 
  • If you want to print the command, the best way to do this is usually with set -x :

    install -x curl " https://www.facebook.com/vivekkumar27june88 "> ~ / Desktop / fb.html set + x

    ... but you can also do something similar using an array approach if you need to:

     printf "%q " "${curlCmd[@]}" # Print the array, quoting as needed printf "\n" "${curlCmd[@]}" > ~/Desktop/fb.html 
+1
source

Install the following software in ubuntu 14.04

  • sudo apt-get install php5-curl
  • sudo apt-get install curl

then run sudo service apache2 restart check that your phpinfo () is enabled using curl "cURL support: enabled"

Then check your command in a shell script

RESULT = curl -L "http://sitename.com/dashboard/?show=api&action=queue_proc&key=$JOBID" 2>/dev/null

echo $ RESULT

You will get an answer;

Thanks.

0
source

All Articles