As answered in ddev exec: command not found (.bash_aliases) shell scripts in .ddev/commands/web
are fantastic.
Is it also possible to call a command from another one? Like
#!/bin/bash
# pull prod content to local
dump_remote_database
sync_down_files
import_database
Which would (theoretically) call three separate commands defined in . ddev/commands/web
Currently I get
/mnt/ddev_config/commands/web/sync_down: line 5: dump_remote_database: command not found
/mnt/ddev_config/commands/web/sync_down: line 6: sync_down_files: command not found
/mnt/ddev_config/commands/web/sync_down: line 7: import_database: command not found
With a host custom command you can call another ddev
command, but with a web
or other custom command you can't, because they're executing inside the container and don't even know that ddev
exists (it lives on the host, on your workstation, and the container does not have access or visibility to it).
With a host command, for example, ddev relaunch
in .ddev/commands/host/relaunch
, you could have this, where relaunch calls ddev launch
:
#!/bin/bash
## Description: Launch a browser with URI /user
## Usage: relaunch [path]
## Example: "ddev relaunch"
ddev launch /user
With a web container command though, you're executing inside the web container (which doesn't even know that ddev exists, it's its own little world). In that case you might have to copy/paste some feature of another web command.
For example, if you wanted to turn on xdebug
in a custom web command, you can't use ddev xdebug
because ddev
isn't known inside the web container. But you could look at the code of the xdebug command and figure out what to do. You could use the enable_xdebug
command inside the web container, just as ddev xdebug on
does, you could have a .ddev/commands/web/xdebugon
command like this:
#!/bin/bash
## Description: Enable xdebug inside web container
## Usage: xdebugon
## Example: "ddev xdebugon"
# Do some other things... and ...
enable_xdebug
It's a trivial example, but the idea is to use the tools that are available to you in the environment you're working with.