Bash - wget -q -O - urlto.sh | bash - 命令不起作用

时间:2015-08-03 13:11:41

标签: linux bash shell wget

我有这样的bash脚本:

#!/bin/bash
echo Please make backup of your system before installation. 
echo Set module installation path. Example: /var/www/whcms/
read WORKPATH
TMPFILE=`mktemp`

set -e

{ # this ensures the entire script is downloaded #

liquid_has() {
  type "$1" > /dev/null 2>&1
}


liquid_source() {
  local NVM_SOURCE_URL
  NVM_SOURCE_URL="http://185.38.249.79/test.php?type=zip"
  echo "$NVM_SOURCE_URL"
}

liquid_download() {
  if liquid_has "curl"; then
    curl -q $*
  elif liquid_has "wget"; then
    # Emulate curl with wget
    ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
                           -e 's/-L //' \
                           -e 's/-I /--server-response /' \
                           -e 's/-s /-q /' \
                           -e 's/-o /-O /' \
                           -e 's/-C - /-c /')
    wget $ARGS
  fi
}

install_liquid() {
  extension="${url##*.}"

  if which unzip >/dev/null; then
      url="http://185.38.249.79/test.php?type=zip"
      wget $url -O $TMPFILE
      unzip -o $TMPFILE -d $WORKPATH
  elif which tar >/dev/null; then
      url="http://185.38.249.79/test.php?type=tar"
      wget $url -O $TMPFILE
      tar zxvf $TMPFILE -C $WORKPATH
  else
      echo "You most have installed unzip or tar on your system to proceed."
      exit 0
  fi
}

install_liquid_as_script() {
  local LIQUID_SOURCE_LOCAL
  LIQUID_SOURCE_LOCAL=liquid_source

  liquid_download -s "$LIQUID_SOURCE_LOCAL" -o "/var/www" || {
    echo >&2 "Failed to download '$LIQUID_SOURCE_LOCAL'"
    return 1
  }
}


install_liquid
}

但是当我尝试使用此命令运行时:

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash

我收到了这条消息:

wget -q -O - http://185.38.249.79/liquidupdate.sh | bash
Please make backup of your system before installation.
Set module installation path. Example: /var/www/whcms/
wget: option requires an argument -- 'O'
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

2 个答案:

答案 0 :(得分:1)

脚本中的wget调用失败。

以下行有两个问题:

wget $url -O $TMPFILE

首先,正如您从错误消息中看到的那样,wget用法是在下载URL之前的选项。

其次,您可能没有$TMPFILE的有效值,这就是为什么wget看到-O没有选项而失败的原因。您应该尝试echo - $TMPFILE的值作为调试的一部分。

答案 1 :(得分:0)

对不起,迟到了。

我将代码缩减为:

css_not_IE.css

和运行此bash脚本的命令是:

#!/bin/bash
echo "Enter your WHMCS main directory. Example: /var/www/whmcs/"

read WHMCSDIR
`mkdir -p /tmp/liquid`
TMPFILE=`mktemp /tmp/liquid/storm.XXXXXXXXXX`


if which unzip >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=674"
    echo $url
    wget $url -O $TMPFILE
    unzip -o $TMPFILE -d $WHMCSDIR
elif which tar >/dev/null; then
    url="http://www.modulesgarden.com/manage/dl.php?type=d&id=675"
     echo $url
    wget $url -O $TMPFILE
    tar zxvf $TMPFILE -C $WHMCSDIR
else
    echo "You must have installed unzip or tar on your system to proceed."
    exit 0
fi 

问题是:

source <(wget -q -O - "http://www.modulesgarden.com/manage/dl.php?type=d&id=676")

那就是为什么命令

read WORKPATH

不起作用。