问题描述
在本地ddev实例中,我向 .ddev / homeadditions / bash_aliases
添加了一些别名和功能。
In a local ddev instance, I have added a few aliases and functions to .ddev/homeadditions/bash_aliases
.
例如: alias ll = ls -lhA
同时 ddev ssh
然后 ll
将起作用, ddev exec ll
返回
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
为什么?
推荐答案
这实际上与bash的工作方式有关,而不是ddev的工作方式。 .bashrc(因此由.bashrc加载的.bash_aliases)仅由 interactive 外壳程序(如 ddev ssh
这样的外壳程序加载)。这是一个关于堆栈溢出的答案:
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
只能执行 bash -c< your command>
,而 bash -c
在设计上是非交互的。
ddev exec
just does a bash -c "<your command>"
, and bash -c
is noninteractive by design.
您可能会考虑添加ddev自定义Web命令来处理您无法摆脱的生活。
You might consider adding ddev custom web commands for things you can't live without.
A ddev ll
定制命令可以像这样工作。在.ddev / commands / web中使用内容创建一个名为 ll的文件
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 $@
这篇关于ddev exec:找不到命令(.bash_aliases)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!