function drush_process_bootstrap_to_first_arg

8.0.x drush_process_bootstrap_to_first_arg(&$arguments)
6.x drush_process_bootstrap_to_first_arg(&$arguments)
7.x drush_process_bootstrap_to_first_arg(&$arguments)
4.x drush_process_bootstrap_to_first_arg(&$arguments)
5.x drush_process_bootstrap_to_first_arg(&$arguments)
master drush_process_bootstrap_to_first_arg(&$arguments)

Process the --bootstrap-to-first-arg option, if it is present.

This option checks to see if the first user-provided argument is an alias or site specification; if it is, it will be shifted into the first argument position, where it will specify the site to bootstrap. The result of this is that if your shebang line looks like this:

#!/path/to/drush --bootstrap-to-first-arg php-script

Then when you run that script, you can optionally provide an alias such as @dev as the first argument (e.g. $ ./mydrushscript.php @dev scriptarg1 scriptarg2). Since this is the behavior that one would usually want, it is default behavior for a canonical script. That is, a script with a simple shebang line, like so:


will implicitly have "--bootstrap-to-first-arg" and "php-script" prepended, and will therefore behave exactly like the first example. To write a script that does not use --bootstrap-to-first-arg, then the drush command or at least one flag must be explicitly included, like so:

#!/path/to/drush php-script

1 call to drush_process_bootstrap_to_first_arg()
drush_parse_args in includes/
Parse console arguments.


includes/, line 932
The drush command engine.


function drush_process_bootstrap_to_first_arg(&$arguments) {
  if (drush_get_option('bootstrap-to-first-arg', FALSE)) {
    $shift_alias_pos = 1 + (drush_get_context('DRUSH_SHEBANG_SCRIPT') === TRUE);
    if (sizeof($arguments) >= $shift_alias_pos) {
      $shifted_alias = $arguments[$shift_alias_pos];
      $alias_record = drush_sitealias_get_record($shifted_alias);
      if (!empty($alias_record)) {
        // Move the alias we shifted from its current position
        // in the argument list to the front of the list
        array_splice($arguments, $shift_alias_pos, 1);
        array_unshift($arguments, $shifted_alias);