25

I am trying to write a Drush script to enable a bunch of modules based on a hook. If it's already enabled, I would rather skip enabling that module.

Is there a way for Drush to return whether or not a module is enabled?

37

This code will list all non core enabled modules:

drush pm-list --pipe --type=module --status=enabled --no-core
2
  • 8
    +1; and you can even pipe the results to find command like this: drush pm-list --pipe --type=module --status=enabled --no-core | find /I "views_ui" - in this example, if "views_ui" is enabled, it returns views_ui, else it returns an empty result set (nothing).
    – Sk8erPeter
    Sep 1 '13 at 22:44
  • @Sk8erPeter grep seems more efficient for this case
    – MediaVince
    May 30 '18 at 13:40
9
drush pm-info

Gives status of module with additional information as given below:

drush pm-info <module_name>

 Extension        :  <ext>
 Project          :  Unknown
 Type             :  module
 Title            :  <title>
 Description      :  <desc>
 Version          :  6.x-1.0
 Date             :  1970-01-01
 Package          :  <pkg>
 Core             :  6.x
 PHP              :  5.3.5
 Status           :  enabled
 Path             :  <path_to_the_module>
 Schema version   :  <schema_version>
 Requires         :  none
 Required by      :  <list_of_modules_this_module_is_required_by>
 Configure        :  None
1
  • This command was removed in newer versions of Drush. Drush 10 says to instead use pm-list
    – mbomb007
    Jun 18 '20 at 19:45
1

with drush 10 :

drush pm:list --type=module --status=enabled | grep mymodule
0

One liner to get module status:

drush pm-info mymodule | grep Status | cut -d':' -f 2 | xargs

Returns either not installed or enabled

Explanation:

  • drush pm-info mymodule - gets info about the module
  • grep Status - just get the status line
  • cut -d':' -f 2 - get the value after the colon
  • xargs - remove the whitespace

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