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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题