php-eval

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

drush php-eval

Aliases:

Arguments:

code : PHP code

Examples:

Sets the hello variable using Drupal API.

drush php-eval 'variable_set("hello", "world");'

Loads node with nid 1 and then prints its title.

drush php-eval '$node = node_load(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 "file_unmanaged_copy('$HOME/Pictures/image.jpg', 'public://image.jpg');"

Rebuild node access permissions.

drush php-eval "node_access_rebuild();"