Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
From Sacha Chua's weblog entry, Drupal shell: quickly evaluating PHP statements in a Drupal context.
Comment | File | Size | Author |
---|---|---|---|
#5 | drush_eval3.patch | 189 bytes | gabriel. |
#3 | drush_tools_eval_1.patch | 636 bytes | gabriel. |
drush_tools_eval.patch | 519 bytes | christefano |
Comments
Comment #1
gabriel. CreditAttribution: gabriel. commentedjust updating the status :)
way to go, sacha!
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentedI 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.Comment #3
gabriel. CreditAttribution: gabriel. commentedThis 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.)Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedPatch won't apply
Comment #5
gabriel. CreditAttribution: gabriel. commentedok, 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.
Comment #6
moshe weitzman CreditAttribution: moshe weitzman commentedperhaps 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.
Comment #7
gabriel. CreditAttribution: gabriel. commentedit 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.
Comment #8
adrian CreditAttribution: adrian commentedthis exists in HEAD