Support from Acquia helps fund testing for Drupal Acquia logo

Comments

gabriel.’s picture

Status: Active » Needs review

just updating the status :)
way to go, sacha!

moshe weitzman’s picture

Status: Needs review » Active

I added help for this command and committed this to all branches. But it doesn't really work as I would hope. For example, drush eval "print_r($GLOBALS)" does not print anything. I think it cannot deal with the dollar sign. Help wanted.

gabriel.’s picture

Status: Active » Needs review
FileSize
636 bytes

This is probably because bash interprets dollar-signs in double-quoted strings as bash variables. To get around this, you could use single quotes, like so:

drush eval 'print_r($GLOBALS);'

This command works as expected. Otherwise, you can add a backslash before your dollar signs in double-quoted strings for PHP variables. I know it can be annoying, but short of that, I can't think of anything else we can do.

And for the sake of convenience, I've also included a patch that auto-appends a semicolon the end of the command if one isn't there. (I don't know about the rest of you, but it really annoys me to see PHP Parse error: syntax error, unexpected $end in ... every time I'm trying to do a simple one-liner just because I forgot the terminating semicolon.)

moshe weitzman’s picture

Status: Needs review » Needs work

Patch won't apply

gabriel.’s picture

Status: Needs work » Needs review
FileSize
189 bytes

ok, I recreated my patch. looks like drush_tools_eval() is now part of the module, so I just added a patch based on the latest 6.x-dev release.

Now you won't get that annoying nag error if you accidentally leave off a terminating semicolon.

moshe weitzman’s picture

perhaps we should conditionally add the semicolon so we don't ever get two? or maybe two does not matter.

in HEAD, we have now split this command to the drush_extras project. Perhaps it should move to drush project as it will always be version agnostic.

gabriel.’s picture

it doesn't matter if there are two semicolons. I've tested both cases and it still gets interpreted the same way—it just ignores the second one if it ends with two.

adrian’s picture

Version: 5.x-1.3 »
Status: Needs review » Fixed

this exists in HEAD

Moya:drush adrian$ php /Users/adrian/Projects/hosting/drush/drush.php --root='/Users/adrian/Projects/hosting/platforms/DRUPAL-6' --uri='http://includetest.dev'  help eval Run arbitrary PHP code in the context of Drupal

Examples:
  drush eval \"variable_set('hello', 'world');\"	Sets the hello variable using Drupal API.

Arguments:
  code	PHP code

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.