Listing variable values using drush
-
22-01-2021 - |
Question
I would like to list the values of certain variables using Drush in order to make sure they are in fact the variables that I intend to add to my feature. It seems that some variables are parents which contain multiple children. I use a drush/features/git workflow with a purchased but customized theme and following is my example for clarity.
In my feature myfeature_theme_helper
there are two variables that I exported to it: theme__settings
and theme_settings
. I want to be able to view what values each are storing so I can determine if they should be removed from my helper. One of them contains an active tab, for example, which is not a setting that I want to commit to code.
Thank you!
La solution
If you do
drush vget theme_THEMENAME_settings
it will give you all nested variables but nested variables don't work
drush vget theme_THEMENAME_settings.toggle_name
drush vget theme_THEMENAME_settings:toggle_name
so the only way I found to get nested variables is with the use of grep
so for my theme I would do something like this
drush vget theme_THEMENAME_settings | grep toggle_name:
or do further processing using cut to get just the value of this variable
drush vget theme_THEMENAME_settings | grep toggle_name: | cut -f2- -d:
where theme_THEMENAME_settings
is my variable and toggle_name
is the nested variable name
Autres conseils
Even though I like grep a lot, I think it's worth adding new tools to the toolbox from time to time ;-) Using jq and JSON output (instead of Yaml that is the default), you can use:
drush vget --format=json theme_THEMENAME_settings | jq -r '.theme_THEMENAME_settings | .toggle_name'
or the slightly shorter
drush vget --format=json theme_THEMENAME_settings | jq -r '.[] | .toggle_name'