2016-09-01 44 views
0

當我執行這些行:擊:讓網頁內容與捲曲/ wget的變量

res1=$(curl -sSL http://ipecho.net/plain | xargs echo) 
echo $res1 

我得到這個輸出,這意味着實際上,我能放this webpage內容到一個變量:

92.12.242.124 

========================

現在,當我嘗試用相同another URL

res2=$(curl -sSL https://raw.github.com/n-marshall/system-setup/master/common/configs/.gitignore_global | xargs echo) 
echo $res2 

我得到這樣的輸出:

xargs: unterminated quote 

任何人都可以引導我到獲得第二個鏈接的內容到一個變量?謝謝。

(我的實際目標是再複印/追加到本地文件,如果改變任何東西答案)

================= =================

編輯:我一直沒能實現與wget的相同要麼,但wget的任何解決方案是值得歡迎的太

EDIT2 :提供更多的上下文...

我正在尋找一個解決方案,可以:

  • 工作在系統文件(即使用sudo,但重定向沒有發揮使用sudo不錯)
  • 通這個作爲參數傳遞給另一個函數

像這樣的(追加,但增加了一個分隔符):

append() { 
    if [ "$1" = "--separate" ]; then 
     [[ -s $3 ]] && printf "\n#----------------------------------------------------------------\n\n" | sudo tee -a $3 
     echo $2 | sudo tee -a $3 
     printf "\n" | sudo tee -a $3 
    else 
     echo $1 | sudo tee -a $2 
    fi 
} 
+0

' res2 = $(curl -sSL https://raw.github.com/n-marshall/system -setup /主/普通/ CONFIGS/.gitignore_global); echo「$ res2」' – anubhava

+0

嘗試'| xargs -0 echo' – Tom

+0

爲什麼你甚至使用xargs? – 123

回答

1

如果您只想將curl輸出複製到本地文件,則不需要變量。就在curl命令重定向到文件:

curl -sSL https://raw.github.com/n-marshall/system-setup/master/common/configs/.gitignore_global > file 

將輸出追加到現有文件:

curl -sSL https://raw.github.com/n-marshall/system-setup/master/common/configs/.gitignore_global >> file 

編輯

隨着sudo

sudo bash -c 'curl -sSL https://raw.github.com/n-marshall/system-setup/master/common/configs/.gitignore_global > file2' 
+0

這將是很好的評論downvote。 – SLePort

+0

適用於不需要sudo的文件...您是否需要sudo文件的解決方案?順便說一句,我不明白downvote要麼讓我upvote,以彌補 –

+0

謝謝@ n-marshall。我更新了我的答案。 – SLePort