pm-update fails "sh: --backend=2: command not found" The pm-download command is working so I can update modules individually, but I can't do it in bulk. Both drush 6.2.0 and 6.1.0 give an error.

The output of drush up --debug is the following.


  Bootstrap to phase 0. [0.01 sec, 2.24 MB]
  [bootstrap] Drush bootstrap phase : _drush_bootstrap_drush() [0.01
  sec, 2.37 MB] [bootstrap] Cache HIT cid:
  6.2.0-commandfiles-0-da12a99782b48770f5d9ad8965ca5448 [0.02 sec, 2.39 MB]           [debug] Bootstrap to phase 0. [0.09 sec, 6.4 MB]
  [bootstrap] Bootstrap to phase 6. [0.14 sec, 6.4 MB]
  [bootstrap] Drush bootstrap phase : _drush_bootstrap_drupal_root()
  [0.14 sec, 6.41 MB]                     [bootstrap] Initialized Drupal
  7.24 root directory at /path/to/site [0.16 sec, 7.43 MB]    [notice] Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.16 sec, 7.44
  MB]                     [bootstrap] Initialized Drupal site default at
  sites/default [0.16 sec, 7.44 MB]
  [notice] Cache HIT cid:
  6.2.0-install_profile-66ecfeb9791a023150773849f1550c5d [0.16 sec, 7.45 MB]          [debug] Cache HIT cid:
  6.2.0-commandfiles-2-699657487b88e8b0c2ede2984aa12913 [0.16 sec, 7.45 MB]           [debug] Drush bootstrap phase :
  _drush_bootstrap_drupal_configuration() [0.17 sec, 7.47 MB]            [bootstrap] Drush bootstrap phase : _drush_bootstrap_drupal_database()
  [0.17 sec, 7.51 MB]                 [bootstrap] Successfully connected
  to the Drupal database. [0.17 sec, 7.51 MB]
  [bootstrap] Drush bootstrap phase : _drush_bootstrap_drupal_full()
  [0.18 sec, 8.14 MB]                     [bootstrap] Cache HIT cid:
  6.2.0-install_profile-66ecfeb9791a023150773849f1550c5d [0.37 sec, 26.15 MB]         [debug] Cache HIT cid: 6.2.0-commandfiles-5-8aee30ce3a469e89d0725cfb79ceb51b [0.37 sec, 26.16 MB]          [debug] Drush bootstrap phase :
  _drush_bootstrap_drupal_login() [0.38 sec, 26.62 MB]                   [bootstrap] Successfully logged into Drupal as Guest (uid=0) [0.38
  sec, 26.63 MB]                          [bootstrap] Found command:
  pm-update (commandfile=pm) [0.38 sec, 26.63 MB]
  [bootstrap] Calling hook drush_pm_update [0.71 sec, 26.97 MB]
  [debug] Loading release_info engine. [0.9 sec, 29.07 MB]
  [notice] Loading version_control engine. [0.9 sec, 29.17 MB]
  [notice] Loading package_handler engine. [0.91 sec, 29.19 MB]
  [notice] Executing: wget --version Including
  /usr/local/Cellar/drush/6.2.0/libexec/commands/pm/updatecode.pm.inc
  [0.93 sec, 29.21 [bootstrap] MB] Calling hook
  drush_pm_updatecode_validate [0.94 sec, 29.31 MB]
  [debug] Returned from hook drush_pm_updatecode_validate [0.94 sec,
  29.31 MB]                               [debug] Calling hook drush_pm_updatecode [0.94 sec, 29.32 MB]
  [debug] Cache HIT cid:
  6.2.0-alias-path--2c8463220c4fed24dfb54242bc0f682e [0.94 sec, 29.36 MB]             [debug] Backend invoke:   --backend=2 --verbose
  --debug --root=/path/to/site          [command]
  --uri=site.local  pm-updatestatus 2>&amp;1 [1.26 sec, 29.37 MB]   --backend=2 --verbose --debug --root=/path/to/site --uri=site.local            [notice] pm-updatestatus 2>&amp;1 [1.26 sec, 29.38 MB] Illegal string
  offset 'site' backend.inc:1013 [1.27 sec, 29.38 MB]
  [warning] The command could not be executed successfully (returned:
  sh: --backend=2: command not found   [error] , code: 127) [1.27 sec,
  29.38 MB] Returned from hook drush_pm_updatecode [1.27 sec, 29.36 MB]                                        [debug] Changes made in drush_pm_updatecode have been rolled back.
  [1.27 sec, 29.37 MB]                 [rollback] Command dispatch
  complete [1.27 sec, 29.34 MB]
  [notice] Returned from hook drush_pm_update [1.28 sec, 27.27 MB]
  [debug] Command dispatch complete [1.28 sec, 27.24 MB]
  [notice]  Timer  Cum (sec)  Count  Avg (msec)   page   1.113      1
  1113.33 Peak memory usage was 31.64 MB [1.28 sec, 27.24 MB]                                               [memory]


The issue happens under OS X Mountain Lion and PHP 5.4.20, and continued after upgrading to Mavericks.
This is happening because Drush is trying to find the local Drush executable via $drush = realpath($_SERVER['argv']['0']);.  In this context, realpath is returning FALSE, because $_SERVER['argv']['0'] does not exist.

As a workaround for this particular problem (which is that pm-update cannot call updatedb), you could run drush pm-updatecode followed by drush updatedb.

Note

If you work around the problem instead of solving it, you will also run into this same issue with other commands, such as sql-sync.