drush php-evalfor drush 8x


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

drush php-eval

  • Aliases


    php-eval has 2 alias/es:


    drush eval

    drush ev

  • Arguments


    php-eval accepts 1 argument/s:


    code : PHP code

  • Options


    php-eval accepts 18 option/s:


    --format : Select output format. Available: json, csv, html, list, string, table, var_export, yaml. Default is json.

    --fields : Fields to output.

    --list-separator : Specify how elements in a list should be separated. In lists of lists, this applies to the elements in the inner lists.

    --line-separator : In nested lists of lists, specify how the outer lists ("lines") should be separated.

    --field-labels : Add field labels before first line of data. Default is on; use --no-field-labels to disable.

    --format=json : Javascript Object Notation.

    --format=config : A configuration file in executable php format. The variable name is "config", and the variable keys are taken from the output data array's keys.

    --format=csv : A list of values, one per row, each of which is a comma-separated list of values.

    --format=html : An HTML representation

    --format=labeled-export : A list of php exports, labeled with a name.

    --format=list : A simple list of values.

    --format=php : A serialized php string.

    --format=print-r : Output via php print_r function.

    --format=string : A simple string.

    --format=table : A formatted, word-wrapped table.

    --format=var_export : An array in executable php format.

    --format=variables : A list of php variable assignments.

    --format=yaml : Yaml output format.

  • 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();"

  • Comments


    comments powered by Disqus