php:eval¶
Evaluate arbitrary php code after bootstrapping Drupal (if available).
Examples¶
drush php:eval '$node = \Drupal\node\Entity\Node::load(1); print $node->getTitle();'
. Loads node with nid 1 and then prints its title.drush php:eval "\Drupal::service('file_system')->copy('$HOME/Pictures/image.jpg', 'public://image.jpg');"
. Copies a file whose path is determined by an environment's variable. Use of double quotes so the variable $HOME gets replaced by its value.drush php:eval "node_access_rebuild();"
. Rebuild node access permissions.
Arguments¶
- code. PHP code. If shell escaping gets too tedious, consider using the php:script command.
Options¶
- --format[=FORMAT]. [default: var_export]
Aliases¶
- eval
- ev
- php-eval
Legend
- An argument or option with square brackets is optional.
- Any default value is listed at end of arg/option description.
- An ellipsis indicates that an argument accepts multiple values separated by a space.