Bash : 使用 curl / wget 获取网页内容到变量中

Bash : getting webpage content into variable with curl / 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

谁能指导我将第二个 link 的内容放入变量中?谢谢。

(我的实际目标是然后将其复制/附加到本地文件,如果这对答案有任何改变的话)

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

编辑:我也无法使用 wget 实现相同的效果,但也欢迎使用 wget 的任何解决方案

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

我正在寻找可以实现的解决方案:

像这个(附加但添加分隔符):

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

如果您只想将 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'