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 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算