bash - “Syntax error”单词意外

标签 bash syntax-error

  # Licensed to the Apache Software Foundation (ASF) under one
  # or more contributor license agreements.  See the NOTICE file
  # distributed with this work for additional information
  # regarding copyright ownership.  The ASF licenses this file
  # to you under the Apache License, Version 2.0 (the
  # "License"); you may not use this file except in compliance
  # with the License.  You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.

  calculate_heap_sizes()
  {
    case "`uname`" in
     Linux)
        system_memory_in_mb=`free -m | awk '/:/ {print $2;exit}'`
        system_cpu_cores=`egrep -c 'processor([[:space:]]+):.*' /proc/cpuinfo`
    ;;
    FreeBSD)
        system_memory_in_bytes=`sysctl hw.physmem | awk '{print $2}'`
        system_memory_in_mb=`expr $system_memory_in_bytes / 1024 / 1024`
        system_cpu_cores=`sysctl hw.ncpu | awk '{print $2}'`
    ;;
    SunOS)
        system_memory_in_mb=`prtconf | awk '/Memory size:/ {print $3}'`
        system_cpu_cores=`psrinfo | wc -l`
    ;;
    Darwin)
        system_memory_in_bytes=`sysctl hw.memsize | awk '{print $2}'`
        system_memory_in_mb=`expr $system_memory_in_bytes / 1024 / 1024`
        system_cpu_cores=`sysctl hw.ncpu | awk '{print $2}'`
    ;;
    *)
        # assume reasonable defaults for e.g. a modern desktop or
        # cheap server
        system_memory_in_mb="2048"
        system_cpu_cores="2"
    ;;
   esac

     .....................

这是dse4.5.2中的默认cassandra-env.sh

当我启动cassandra时,它说:
  : not foundinstallables/dse-4.5.2/resources/cassandra/bin/cassandra: 16:  
  /usr/local/installables/dse-4.5.2/resources/cassandra/conf/cassandra-
  env.sh:

  : not foundinstallables/dse-4.5.2/resources/cassandra/bin/cassandra: 18: 
  /usr/local/installables/dse-4.5.2/resources/cassandra/conf/cassandra-
  env.sh: {

  /usr/local/installables/dse-4.5.2/resources/cassandra/bin/cassandra: 19: 
  /usr/local/installables/dse-4.5.2/resources/cassandra/conf/cassandra-
  env.sh: Syntax error: word unexpected (expecting "in")

事后我可以看到“中”。此错误表示什么?有什么帮助吗?

最佳答案

检查行尾。

Windows使用CR LF(^ M ^ J)标记行尾。类似Unix的系统仅使用LF(^ J)。

在具有Windows样式的行尾的脚本中,^M字符将被解释为单词的一部分,而不是空格。例如,一行如下所示:

foo

实际上可能是:
foo^M

(其中^ M是引入Windows样式的行尾的回车符)。该 shell 程序会执行失败,而不是执行foo,而不是执行命令foo^M(假定存在)。错误信息:
foo^M: Command not found

看起来像:
: Command not found

因为在打印^ M时它将光标移至行的开头,从而导致部分错误消息被覆盖。

使用unix2dostr -d '\r'固定行尾。 (首先阅读unix2dos的手册页;与大多数Unix过滤器程序不同,它默认替换其输入文件,而不是写入标准输出。)

关于bash - “Syntax error”单词意外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28980002/

相关文章:

可以通过 bash 添加磁力链接的 Linux torrent 客户端

c - 错误: expected identifier or '(' with C array declaration

syntax-error - flex/bison总是 “syntax error in line 1”

c - C 中意外标记 '(' 附近的语法错误

regex - 从目录树列表中过滤特定行

bash - shell脚本中全局变量的作用域

bash - 从文件名获取日期并分类到文件夹中?

python - uPnP 将视频推送到 OSX/Mac 上的智能电视/三星电视

php - WordPress自定义字段在single.php中的位置

haskell - Haskell列表生成器中的生成器不起作用