drush php-eval

Evaluate arbitrary php code after bootstrapping Drupal (if available).

Drush Command

drush php-eval

Arguments

code : PHP code

Aliases

drush eval
drush ev

Options

--format : [object Object]
--fields : [object Object]
--list-separator : [object Object]
--line-separator : [object Object]
--field-labels : [object Object]
--format=json : [object Object]
--format=config : [object Object]
--format=csv : [object Object]
--format=html : [object Object]
--format=labeled-export : [object Object]
--format=list : [object Object]
--format=php : [object Object]
--format=print-r : [object Object]
--format=string : [object Object]
--format=table : [object Object]
--format=var_export : [object Object]
--format=variables : [object Object]
--format=yaml : [object Object]

Examples

Sets the hello variable using Drupal API.

drush php-eval 'variableset("hello", "world");'
Loads node with nid 1 and then prints its title.
drush php-eval '$node = nodeload(1); print $node->title;'
Copies a file whose path is determined by an environment's variable. Note the use of double quotes so the variable $HOME gets replaced by its value.
drush php-eval "fileunmanagedcopy('$HOME/Pictures/image.jpg', 'public://image.jpg');"
Rebuild node access permissions.
drush php-eval "nodeaccessrebuild();"