Last Updated: March 26, 2019
· lwalley

Using drush vset with arrays

drush is a great command line tool for Drupal. Drupal stores persistent variables in a site's database. Using drush vget (variable-get) and drush vset (variable-set) commands it is easy to read and update the values of these persistent variables from the command line. For example, getting and setting the site_name string is simple:

drush vget site_name
drush vset site_name "New site name"

Setting variables that contain array values is not as obvious. However, the instructions on setting a variable to a complex value using json is available in drush help:

drush help vset

Just convert the array to json string and then use vset with the --format=json option. For example, to set update_notify_emails array use the following one liner:

php -r "print json_encode(array(''));" | drush vset --format=json update_notify_emails -

1 Response
Add your response


Hi Lisa - I couldn't get the variable to set, but it could be due to the version of drush. Instead I used drush php-eval like so:

drush php-eval "variable_set('update_notify_emails', array(''));"
about 2 months ago ·