2

In a bash script I use drush site-set @foo_alias to simplify subsequent drush commands.

I would like to compile my SaSS files using compass compile $(drush dd my_theme). However, for this case I have to explicitly specify the alias as in compass compile $(drush @foo_alias dd my_theme).

Otherwise, I get an error message:

You need to specify an alias or run this command within a drupal site.

Target 'my_theme' not found.

Is there a bash syntax that obviates the need for the alias in the drush dd command?

3

There are several ways to specify which Drupal site Drush will target; the alias is probably the simplest.

The second option is more verbose, but it does not require an alias file. Run:

$(drush --root=/path/to/drupal --uri=http://mysite.com dd my_theme)

You can do the same thing with a slightly different syntax:

$(drush /path/to/drupal#mysite.com dd my_theme)

You can also specify the Drupal site implicitly, by setting the cwd to the folder that contains the settings.php file for your site:

cd /path/to/drupal/sites/default # or /path/to/drupal/sites/mysite.com, as appropriate
$(drush dd my_theme)

A distant fourth option would be to use the site-set command; that would be a bad idea, though, as it uses the current process id to identify the filename that stores the current Drupal site. If your bash script created any subprocesses (e.g. by wrapping sections of the script in parenthesis, using $(), using backticks, etc.), then commands inside the subprocess will "forget" the currently set site.

For example, the following script will only print the site that was set once; the portion of the script inside parenthesis fails to find the set site:

drush site-set @foo_alias
echo "process $BASHPID"
drush ev 'return drush_sitealias_site_get();'
(
  echo "subprocess $BASHPID"
  drush ev 'return drush_sitealias_site_get();'
)

In a script, you are better off putting the site specification into a variable, and explicitly use that variable with every invocation of Drush.

  • Greg - thanks for the response. I already have variables in my bash script that I can concatenate to define the site alias so that isn't a problem. I'm more interested in why some drush commands work inside bash scripts with the current default alias and why others (like dd) do not. – Adam Carter May 1 '14 at 6:35
  • I corrected my answer. – greg_1_anderson May 1 '14 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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