ddev exec: command not found (.bash_aliases)

南楼画角 提交于 2020-03-05 00:25:04

问题


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?


回答1:


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 $@



回答2:


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.



来源:https://stackoverflow.com/questions/60217324/ddev-exec-command-not-found-bash-aliases

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!