Skip to content

Root file and shebang

Using a custom root file

By default castor looks for a castor.php or .castor/castor.php file in the current working directory or one of its parents.

However you can use another root file by using the --castor-file option:

castor --castor-file=path/to/your-file.php your-task

Using a shebang line

Unix systems support shebang lines to execute scripts directly from the command line, without having to prefix them with the interpreter.

The --castor-file option makes it possible to create a Castor file that can be executed directly. For example, you can create a file named my-script with the following content:

#!/usr/bin/env -S castor --castor-file
<?php

use Castor\Attribute\AsTask;

use function Castor\io;

#[AsTask()]
function shebangTask(): void
{
    io()->writeln('Hello from shebang task!');
}

Make sure to give execute permissions to your script:

chmod +x my-script

Now, you can run your script directly from the command line:

./my-script shebang-task