To export more than one rule, but only the rules whose name is given in a list, I would use the following code.
#!/usr/bin/bash
# The list of item names to export
items=(item1 item2 item3)
for item in "${items[@]}"; do
drush rules-export "$item" > "${item}.txt"
done
This is simpler than getting the list of existing rules from drush rules-list --pipe
, remove the items in that list that don't match the rule names you want to export, and then run drush rules-export
on the left items.
If you had a list of names, which could be either component names or rule names, and you wanted to export only rules, the code would be similar to the following one.
#!/usr/bin/bash
# The list of items to export, which could include component names
names=(name1 name2 name3)
# Get a list of rule names only, and convert it in an array.
rules=( $(drush rules-list --pipe --type=rule) )
# Create an array with items that are in both the arrays.
exports=( $(comm -12 <(printf '%s\n' "${names[@]}" | LC_ALL=C sort) <(printf '%s\n' "${rules[@]}" | LC_ALL=C sort)) )
# Export the items whose names are in the exports array, which contains only rule names.
for export in "${exports[@]}"; do
drush rules-export "$export" > "${export}.txt"
done