从Mac OS X Yosemite

时间:2015-09-09 01:44:27

标签: bash shell

从命令行,我可以使用如下命令启动Neo4j:

~/neo4j/bin/neo4j start

如何在shell脚本中执行此操作?

start.sh

# Define defaults
path_default="~/neo4j/bin/neo4j"
port_default="7474"
pass_default="1234"

# Ask for custom values
read -p "Enter path to neo4j [$path_default]: " path
path="${path:-$path_default}"
read -p "Enter port to neo4j [$port_default]: " port
port="${port:-$port_default}"
read -p "Enter password for neo4j [$pass_default]: " pass
pass="${pass:-$pass_default}"

if !(lsof -t -i:$port); then
  echo "Starting Neo4j"
  "$path start" #THIS IS NOT WORKING
fi

运行./start.sh时出现以下错误:

./start.sh: line 16: ~/neo4j/bin/neo4j start: No such file or directory

编辑:在Mac OS X上,如果我使用/Users/$USER/neo4j/bin/neo4j而不是~/neo4j/bin/neo4j,一切正常。因此,如果用户在Mac上输入以~开头的路径,解决我的问题的一种方法是将/Users/$USER转换为~。但是这适用于所有平台吗?

编辑:根据@DannyDaglas的建议,我将start.sh脚本改为:

#!/bin/bash

# Define defaults
path_default="~/neo4j/bin/neo4j"
port_default="7474"

# Ask for custom values
read -p "Enter path to neo4j [$path_default]: " path
path="${path:-$path_default}"
read -p "Enter port to neo4j [$port_default]: " port
port="${port:-$port_default}"

if !(lsof -t -i:$port); then
  echo "Starting Neo4j at $path"
  $(cd / ; ls $path) start
fi

这仍然失败。当我接受默认值时,这是终端中的输出:

$ ./start.sh
Enter path to neo4j [~/neo4j/bin/neo4j]: 
Enter port to neo4j [7474]: 
Starting Neo4j at ~/neo4j/bin/neo4j
ls: ~/neo4j/bin/neo4j: No such file or directory
./start.sh: line 38: start: command not found

注意:这是在Mac OS 10.10.5 Yosemite的新安装中。

1 个答案:

答案 0 :(得分:-1)

消除双引号:

$(document).ready(function () {
          $("#btnAdd").click(function () {
            addExpression();
          });
          $("body").on("click", "ul.expression li", function () {
             $("ul.expression li").removeClass("highlight");
             $(this).addClass("highlight");
             });
        });
        function addExpression() {
            $('ul#mainList').append("<li><a>test</a></li)");
        }