0

In a local ddev instance, I have added a few aliases and functions to .ddev/homeadditions/bash_aliases.

For example: alias ll="ls -lhA"

While ddev ssh and then ll will work, ddev exec ll returns

bash: ll: command not found
Failed to execute command ll: exit status 127

Why?

Urs
  • 4,984
  • 7
  • 54
  • 116

2 Answers2

3

It's really about how bash works, not about how ddev works. The .bashrc (and thus .bash_aliases, which gets loaded by .bashrc) is only loaded by interactive shells (contexts like ddev ssh). Here'a an Stack Overflow answer on it: Why aliases in a non-interactive Bash shell do not work

ddev exec just does a bash -c "<your command>", and bash -c is noninteractive by design.

You might consider adding ddev custom web commands for things you can't live without.

A ddev ll custom command could work like this. Create a file named "ll" in .ddev/commands/web with the contents

#!/bin/bash

## Description: Run ls -l inside web container
## Usage: ll [flags] [arguments]
## Example: "ddev ll"  or `ddev ll /tmp`

ls -l $@
rfay
  • 9,963
  • 1
  • 47
  • 89
0

Here's an example of my setup (actually, I have scripts more than just ll)

.ddev/docker-compose.env.yaml

version: '3.6'


services:
  web:
    environment:
    - PROD_USER=foo
    - PROD_SERVER=bar.com
    - PROD_ROOT=path/to/root
    - LOCAL_ROOT=that/path/to/root
    - ASSET_DIRS=bi ba bu

.ddev/commands/web/sync_down_files

#!/bin/bash

# rsync prod assets to local

# download all assets
for directory in ${ASSET_DIRS} ; do
    rsync -zra \
        --delete \
        --exclude='.env' \
        ${PROD_USER}@${PROD_SERVER}:/home/${PROD_USER}/${PROD_ROOT}/$directory \
        ${LOCAL_ROOT};
done

Now I do ddev sync_down_files and get all remote assets into the local site. Same for the db.

Urs
  • 4,984
  • 7
  • 54
  • 116