function _drush_bootstrap_drush

6.x _drush_bootstrap_drush()
3.x _drush_bootstrap_drush()
4.x _drush_bootstrap_drush()
5.x _drush_bootstrap_drush()

Initial Drush bootstrap phase.

During the initialization of Drush, this is the first step where all we are aware of is Drush itself.

In this step we will register the shutdown function, parse the command line arguments and store them in their related contexts.

Configuration files (drushrc.php) that are a) Specified on the command line b) Stored in the root directory of drush.php c) Stored in the home directory of the system user.

Additionally the DRUSH_QUIET and DRUSH_BACKEND contexts, will be evaluated now, as they need to be set very early in the execution flow to be able to take affect/

1 string reference to '_drush_bootstrap_drush'
_drush_bootstrap_phases in includes/
Helper function listing phases.


includes/, line 385
Functions used by drush to query the environment and setting the current configuration.


function _drush_bootstrap_drush() {
  // The bootstrap can fail silently, so we catch that in a shutdown function.

  // Set the terminal width, used for wrapping table output.
  // Normally this is exported using tput in the drush script.
  // If this is not present we do an additional check using stty here.
  if (!($columns = getenv('COLUMNS'))) {
    exec('stty size 2>&1', $stty_output, $stty_status);
    if (!$stty_status) {
      $columns = preg_replace('/\d+\s(\d+)/', '$1', $stty_output[0], -1, $stty_count);
    // If stty failed, or we couldn't parse it's output, we assume 80 columns.
    if ($stty_status || !$stty_count) {
      $columns = 80;
  drush_set_context('DRUSH_COLUMNS', $columns);

  // parse the command line arguments.

  // statically define a way to call drush again
  define('DRUSH_COMMAND', drush_find_drush());

  $drush_info = drush_read_drush_info();
  define('DRUSH_VERSION', $drush_info['drush_version']);

  // Load a drushrc.php file in the drush.php's directory.

  // Load a drushrc.php file in the $ETC_PREFIX/etc/drush directory.

  // Load a drushrc.php file at ~/.drushrc.php

  // Load a drushrc.php file in the ~/.drush directory.

  // Load a custom config specified with the --config option.

  // Process the site alias that specifies which instance
  // of drush (local or remote) this command will operate on.
  // We must do this after we load our config files (so that
  // site aliases are available), but before the rest
  // of the drush and drupal root bootstrap phases are
  // done, since site aliases may set option values that
  // affect these phases.
  // TODO: Note that this function will call drush_locate_root
  // (from within _drush_sitealias_find_record_for_local_site),
  // and drush_locate_root will be called again when bootstrapping
  // the drupal root below.  Is there a good way to refactor this
  // so that we do not need to search for the root twice?

  $backend = drush_set_context('DRUSH_BACKEND', drush_get_option(array('b', 'backend')));

  if ($backend) {
    // Load options passed as a JSON encoded string through STDIN.
    $stdin_options = _drush_backend_get_stdin();
    if (is_array($stdin_options)) {
      drush_set_context('stdin', $stdin_options);

  // Pipe implies quiet.
  $quiet = drush_set_context('DRUSH_QUIET', drush_get_option(array('q', 'quiet', 'p', 'pipe')));

  drush_set_context('DRUSH_PIPE', drush_get_option(array('p', 'pipe')));

  // When running in backend mode, all output is buffered, and returned
  // as a property of a JSON encoded associative array.
  if ($backend || $quiet) {


  // Find any command files that are available during this bootstrap phase.