【问题标题】:why do I get errors when running this shell script in terminal?为什么在终端中运行此 shell 脚本时会出现错误?
【发布时间】:2011-07-13 20:56:56
【问题描述】:

我正在尝试让 Doctrine 2 与 Codeigniter 2 一起使用,但在尝试启动并运行 Doctrine 控制台时遇到了一个问题,这涉及执行一个运行几行 php 的 shell 脚本。

我以此作为参考: Integrating Doctrine 2 with CodeIgniter 2

我是 OSX 的新手和 unix 命令的新手,但我确信我已经正确设置了 shell 脚本,如下所示:

#!/usr/bin/env php
<?php
chdir(dirname(__FILE__));
include('doctrine.php');

我在同一个目录中有php文件doctrine.php。

每当我尝试运行脚本时:

bash doctrine

我收到此错误:

doctrine: line 2: ?php: No such file or directory
doctrine: line 3: syntax error near unexpected token `dirname'
doctrine: line 3: `chdir(dirname(__FILE__));'

在我看来,php 甚至根本没有运行。我觉得我做错了一些相当基本的错误!

任何帮助表示赞赏, 标记。

【问题讨论】:

    标签: php macos terminal doctrine-orm


    【解决方案1】:

    这是一个 PHP 脚本,而不是 bash 脚本。

    php doctrine
    

    如果您打算使用 shebang 行,那么您需要使其可执行并直接运行。

    chmod +x doctrine
    ./doctrine
    

    【讨论】:

    • 啊,是的,我也尝试在没有 ./ 的情况下执行它 - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 2017-08-08
    • 2018-01-20
    • 1970-01-01
    • 2015-11-03
    • 1970-01-01
    相关资源
    最近更新 更多