AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 843253
Accepted
Hossein
Hossein
Asked: 2016-10-30 10:29:37 +0800 CST2016-10-30 10:29:37 +0800 CST 2016-10-30 10:29:37 +0800 CST

运行简单的 bash 脚本失败并出现语法错误:单词意外(期望“)”)

  • 772

我正在尝试像这样在 ubuntu14.04 中安装 Anaconda3:

seyyedhossein@hossein:~$ sh Anaconda3-4.2.0-Linux-x86_64.sh 

我得到:

Anaconda3-4.2.0-Linux-x86_64.sh: 16: Anaconda3-4.2.0-Linux-x86_64.sh: 0: not found
Anaconda3-4.2.0-Linux-x86_64.sh: 61: Anaconda3-4.2.0-Linux-x86_64.sh: 0: not found
Anaconda3-4.2.0-Linux-x86_64.sh: 75: Anaconda3-4.2.0-Linux-x86_64.sh: Syntax error: word unexpected (expecting ")")

这里有什么问题?
我已成功将其安装在另一个帐户(最初是从该帐户下载的)上。但是当我登录到我的新帐户时,它就无法运行!

更新:
cat 命令的输出:

#!/bin/bash
# Copyright (c) 2012-2016 Continuum Analytics, Inc.
# All rights reserved.
#
# Name: Anaconda3
# Version: 4.2.0
# Packages: 195
# PLAT:  linux-64
# DESCR: 4.1.1-889-g7ce9b7f
# BYTES: 478051940
# LINES: 558
# MD5:   1ee1f5cb1d92a230e59cc5fce0dca5ba

unset LD_LIBRARY_PATH
echo "$0" | grep '\.sh$' >/dev/null
if (( $? )); then
    echo 'Please run using "bash" or "sh", but not "." or "source"' >&2
    return 1
fi

THIS_DIR=$(cd $(dirname $0); pwd)
THIS_FILE=$(basename $0)
THIS_PATH="$THIS_DIR/$THIS_FILE"
PREFIX=$HOME/anaconda3
BATCH=0
FORCE=0

while getopts "bfhp:" x; do
    case "$x" in
        h)
            echo "usage: $0 [options]

Installs Anaconda3 4.2.0

    -b           run install in batch mode (without manual intervention),
                 it is expected the license terms are agreed upon
    -f           no error if install prefix already exists (force)
    -h           print this help message and exit
    -p PREFIX    install prefix, defaults to $PREFIX
"
            exit 2
            ;;
        b)
            BATCH=1
            ;;
        f)
            FORCE=1
            ;;
        p)
            PREFIX="$OPTARG"
            ;;
        ?)
            echo "Error: did not recognize option, please try -h"
            exit 1
            ;;
    esac
done

# verify the size of the installer
wc -c "$THIS_PATH" | grep 478051940 >/dev/null
if (( $? )); then
    echo "ERROR: size of $THIS_FILE should be 478051940 bytes" >&2
    exit 1
fi

if [[ $BATCH == 0 ]] # interactive mode
then
    if [[ `uname -m` != 'x86_64' ]]; then
        echo -n "WARNING:
    Your operating system appears not to be 64-bit, but you are trying to
    install a 64-bit version of Anaconda3.
    Are sure you want to continue the installation? [yes|no]
[no] >>> "
        read ans
        if [[ ($ans != "yes") && ($ans != "Yes") && ($ans != "YES") &&
              ($ans != "y") && ($ans != "Y") ]]
14.04
  • 3 3 个回答
  • 22870 Views

3 个回答

  • Voted
  1. Best Answer
    zwets
    2016-10-30T11:31:23+08:002016-10-30T11:31:23+08:00

    问题出在脚本上:尽管它在自己的文档中声称它可以由 运行sh,即任何标准 POSIX shell,但它实际上需要bash.

    该构造(( $? ))不是有效的 POSIX sh,也不是($ans != "yes")何时$ans为空。它们在bash任何一个中都几乎无效(TBH,这是我 20 年来第一次看到这个成语(( $? ))),但显然bash让它过去了。

    解决方案:使用 bash 运行:bash Anaconda3-4.2.0-Linux-x86_64.sh

    • 4
  2. heynnema
    2016-10-30T10:35:42+08:002016-10-30T10:35:42+08:00

    您给出的 sh 命令假定 .sh 文件位于您的主目录中。它可能位于其他地方,在这种情况下,您必须为其指定文件所在位置的路径名。

    示例:如果文件 Anaconda3-4.2.0-Linux-x86_64.sh 位于您的桌面上,您可以:

    cd ~/Desktop
    bash Anaconda3-4.2.0-Linux-x86_64.sh
    

    或者

    bash ~/Desktop/Anaconda3-4.2.0-Linux-x86_64.sh
    

    如果这不能解决您的问题,请编辑您的问题以包含以下输出:

    cat Anaconda3-4.2.0-Linux-x86_64.sh | head -n 76
    
    • 1
  3. Hossein
    2016-10-30T11:24:19+08:002016-10-30T11:24:19+08:00

    我使用 bash 而不是 sh,脚本运行得很好!
    似乎 sh 不适合与这个一起使用!

    • 0

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve