Drupal - How to pass argument to php file using a drush command?

This is explained quite nicely in drush topic scripts.

Your script should start with:

#!/usr/bin/env drush
<?php

Then, you may call your script directly. For example, if you have saved your script in a file called myscript, then you would call it via:

$ myscript a b --flag=bar

Drush provides a method called drush_shift that allows you to access you one at a time:

$first = drush_shift();
$second = drush_shift();

In the above example, $first will be a and $second will be b. You may access your options via drush_get_option() as usual.

$flag = drush_get_option('flag');
$other = drush_get_option('other', 'default');

In the above example, $flag is bar and other is `$default'.

Note that you can use $argv as suggested in the other answer, but if you do this, your arguments and options will be mixed together, and you will need to parse them yourself. Using drush_shift() and drush_get_option(); is more convenient.


Posible Solucion:

$_SERVER['argv'][3]

Comand:

drush scr 'testScript.php' field

Now, $_SERVER['argv'][3] = field

Enjoy!

Tags:

Drush