douyue7536 2011-07-13 20:56
浏览 49
已采纳

为什么在终端中运行这个shell脚本时会出错?

I'm trying to get Doctrine 2 working with Codeigniter 2, and have come across a problem while trying to get Doctrine console up and running, which involves executing a shell script which runs a few lines of php.

I'm using this as a reference: Integrating Doctrine 2 with CodeIgniter 2

I'm new to OSX and new to unix commands but I'm confident I have set up the shell script properly as follows:

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

and I have the php file doctrine.php in the same directory.

Whenever I try to run the script with:

bash doctrine

I get this error:

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

It looks to me like php isn't even running at all. I have the feeling I'm doing something fairly basic wrong!

Any help appreciated, Mark.

  • 写回答

1条回答 默认 最新

  • dongzhanbi0027 2011-07-13 20:57
    关注

    It's a PHP script, not a bash script.

    php doctrine
    

    If you meant for the shebang line to be used then you need to make it executable and run it directly.

    chmod +x doctrine
    ./doctrine
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料