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

Viv*_*mar 5 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
Run Code Online (Sandbox Code Playgroud)

运行脚本时出错

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

但是如果直接运行命令那么它工作正常.

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

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

我已经验证了curl库启用了ssl.

Abh*_*hek 14

嵌套在括号内的命令作为子shell运行,因此您的环境变量将丢失.

试试eval:

curlCmd="curl 'https://www.facebook.com/vivekkumar27june88' > ~/Desktop/fb.html"
eval $curlCmd
Run Code Online (Sandbox Code Playgroud)