curl命令不是通过bash中的shell脚本执行的

时间:2015-08-24 11:29:21

标签: linux bash shell curl gnome-terminal

我正在学习shell脚本!同样我尝试在ubuntu终端上使用curl下载facebook页面。

t.sh内容

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

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

但是如果直接运行命令那么它运行正常。

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

如果有人让我知道我在剧本中所犯的错误,我将不胜感激。

我已经确认curl库已启用ssl。

3 个答案:

答案 0 :(得分:13)

嵌入括号中的命令作为子shell 运行,因此您的环境变量将会丢失。

尝试eval:

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

答案 1 :(得分:3)

仅为此单行创建脚本t.sh

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

根据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.

答案 2 :(得分:0)

在ubuntu 14.04中安装以下软件

  1. sudo apt-get install php5-curl
  2. sudo apt-get install curl
  3. 然后运行sudo service apache2 restart 检查你的phpinfo()启用curl&#34; cURL支持:启用&#34;

    然后在shell脚本中检查您的命令

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

    echo $ RESULT

    你会得到回复;

    谢谢你。