6

I would like to configure a module (addtoany) settings with drush. This is the variable:

addtoany_nodetypes: Array
(
    [about_us] => about_us
    [contact] => contact
    [page] => page
    [legal] => 0
    [webform] => 0
)

So that, for instance:

[page] => page
[legal] => 0

becomes

[page] => 0
[legal] => legal

But I am rather new at drush and I am at a complete loss. Thanks for your time.

2 Answers 2

8

Drush does not have any mechanism to convert commandline arguments into php arrays for the variable-set command; however, it is easy to write short php snippets using the php-eval command ('ev' for short).

For example, if you have set up a site alias for your site called "@site":

$ drush @site ev 'variable_set("addtoany_nodetypes", array("about_us" => "about_us", "contact" => "contact", "page" => "page", "legal" => 0, "webform" => 0));'
$ drush @site vget addtoany_nodetypes
addtoany_nodetypes: Array
(
    [about_us] => about_us
    [contact] => contact
    [page] => page
    [legal] => 0
    [webform] => 0
)
$ drush @site ev '$v = variable_get("addtoany_nodetypes", array()); $v["page"] = 0; $v["legal"] = "legal"; variable_set("addtoany_nodetypes", $v);'
$ drush @site vget addtoany_nodetypes
addtoany_nodetypes: Array
(
    [about_us] => about_us
    [contact] => contact
    [page] => 0
    [legal] => legal
    [webform] => 0
)

If you are not using a site alias, then cd to the Drupal root of your site (or cd to the sites folder that contains settings.php if using a multisite) and remove the "@site" from the examples above.

1
  • Exactly what I was looking for, thank you so much @greg_1_anderson !
    – castaway
    Jun 25, 2012 at 21:08
6

As stated in the drush help documentation drush help variable-set the recommended way to set an array variable is using format=json:

php -r "print json_encode(array('drupal', 'simpletest', 'leftandright', 'category'));"  | drush vset --format=json project_dependency_excluded_dependencies -

Don't forget the "-" at the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.