Yet another web developer blog


How to eval PHP code via drush without escaping quotes routine

Very often there is a need to execute via drush eval command the PHP code with both single and double quotes, something like this:

echo "Hello, '$username'!"; 

This can be quickly done without manually adding slashes to each quote in PHP code via this bash trick:

PHP=`cat <<'EOF'
echo "Hello, '$username'!"; 
EOF`; drush ev "$PHP"

Instead of single line of PHP code, you can insert long multi-line part of code, without carrying about escaping quotes.


How to view and revert installed schema version of module in Drupal 8, 9

After executing hook_update_N functions, Drupal stores last version of installed updates in his key-value storage, if update function executed without exceptions.

You can simply lookup installed version via command-line drush command:

drush ev "var_dump(drupal_get_installed_schema_version('my_module'))"

Sometimes you may need revert version to previous, for re-apply updates, or repeat updates, if they previously executed with problems.

You can set previous version of Drupal module schema version via this cli drush command: