0

On ubuntu 18.10 I've problem with a simple script.

If I execute this command directly from shell it works:

drush -y rsync @d8.live:web/sites/default/files @self:sites/default --delete -vv

If I create a .sh script with:

#!/bin/bash
drush -y rsync @d8.live:web/sites/default/files @self:sites/default --delete -vv

The script doesn't work and the drush command returns me an error:

The "--delete" option does not exist.

The command and the script are running from the same directory and the same user.

Where is the problem?

PS: "drush" is a wrapper that executes a docker-compose command

[EDIT]

$ type -a drush
drush ha "drush --strict=0" come alias
drush è /usr/local/bin/drush


$ cat /usr/local/bin/drush
#!/bin/bash
cd $PWD
docker-compose -p example exec --user 82 php drush $@
sergiod
  • 295
  • 1
  • 4
  • 15

2 Answers2

2

Aliases don't get expanded in scripts. If you want the script to include --strict=0 in the command line, you have to say so explicitly in the script.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • unless maybe using `shopt -s expand_aliases` but i agree alias are not needed in a script, the only interest is in interactive shell – Nahuel Fouilleul Feb 07 '19 at 08:08
  • ... or `source ~/.bash_aliases` (even if I think that's ugly) – hek2mgl Feb 07 '19 at 08:09
  • @NahuelFouilleul It's worth mentioning, but the proper solution is really to have scripts which are independent of aliases (and probably to not use aliases a lot at all). – tripleee Feb 07 '19 at 08:10
0

As mentioned here:

$ type -a drush
drush ha "drush --strict=0" come alias
drush è /usr/local/bin/drush

the drush command is within your PATH environmental variable.

Now please make sure that /usr/local/bin folder is part of your `PATH variable, e.g. by:

$ tr : "\n" <<<$PATH | grep usr.local.bin
/usr/local/bin
forest-man
  • 27
  • 2
  • 6