How to set complex string variables with Drush vset

I recently ran into an issue where drush vset was not setting a string variable (in this case, a time period that would be used in strtotime()) correctly:

<br />
# Didn't work:<br />
$ drush vset custom_past_time '-1 day'<br />
Unknown options: --0, --w, --e, --k.  See `drush help variable-set`      [error]<br />
for available options. To suppress this error, add the option<br />
--strict=0.<br />

Using the --strict=0 option resulted in the variable being set to a value of "1".

After scratching my head a bit, trying different ways of escaping the string value, using single and double quotes, etc., I finally realized I could just use variable_set() with drush's php-eval command (shortcut ev):

<br />
# Success!<br />
$ drush ev "variable_set('custom_past_time', '-1 day');"<br />
$ drush vget custom_past_time<br />
custom_past_time: '-1 day'<br />

This worked perfectly and allowed me to go make sure my time was successfully set to one day in the past.

Comments

You just need to escape that - sign, drush is reading it as part of the command.
drush vset custom_past_time '\-1 day' should work fine.