“语法错误”字出乎意料

时间:2015-03-11 06:30:28

标签: 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")

我可以看到""在案件之后。这个错误表明了什么?有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

检查行结尾。

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

看起来像:

unix2dos

因为当打印^ M时,它会将光标发送到行的开头,导致部分错误消息被覆盖。

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