我正在尝试在我的 EC2 Ubuntu 机器上安装 Bazel。我使用
wget
从 最新的 Bazel 发布下载了 .sh 文件,然后使用 sh ./bazel-0.2.1-installer-linux-x86_64.sh
运行它。但是,我遇到了以下错误:
./bazel-0.2.1-installer-linux-x86_64.sh: 106: ./bazel-0.2.1-installer-linux-x86_64.sh: Syntax error: "(" unexpected
查看 .sh 文件中第 106 行,我发现以下代码:function usage() {
。不确定为什么该行中的 (
会出问题。
我尝试使用其他安装程序(bazel-0.2.1-installer-darwin-x86_64.sh
,bazel-0.2.1-jdk7-installer-darwin-x86_64.sh
,bazel-0.2.1-jdk7-installer-linux-x86_64.sh
),它们都在同一行上有相同的问题。
function usage { … }
和usage() { … }
,对吗?不是组合。Bash 手册中的shell functions指示function usage [()] { … }
(大致如此); 也许bash ./bazel-0.2.1-install-linux-x86_64.sh
可以工作? - Jonathan Lefflerfunction usage() {
。 - rafaelcosmanbash
而不是sh
,它起作用了!随意发布答案。 - rafaelcosmansh script
运行脚本,则shebang行不会对程序的运行产生任何影响。只有当您使用./script
(或script
或/path/to/bin/script
)时,shebang行才会发挥作用。但是,如果脚本以#!/bin/bash
开头,则最好使用bash script
而不是sh script
来运行它,因为可能会出现此类问题。 - Jonathan Leffler