Run php in a bash script: error “Could not open input file”

前端 未结 1 1074
长发绾君心
长发绾君心 2021-01-04 11:42

I made a simple script like:

#!/bin/bash
php /var/www/mysite/script1.php
php /var/www/mysite/script2.php

When I run it as root like this:

相关标签:
1条回答
  • 2021-01-04 12:14

    When a batch file passes through some windows-compliant editors or other mishaps, it may happen that carriage return chars are appended to the end of the line (just before linefeed)

    so the all the lines for instance this one:

    php /var/www/mysite/script1.php
    

    contains an invisible \r char which is interpreted as part of the argument py php => file /var/www/mysite/script1.php<invisible char> not found.

    Do the following:

    dos2unix update.sh > newbatchfile.sh
    

    or

    tr -d "\015" < update.sh > newbatchfile.sh
    

    (compare file sizes, if the newbatchfile is smaller, problem was CR chars and is fixed)

    0 讨论(0)
提交回复
热议问题