Regression: Exported Bash function lost after going through another process

こ雲淡風輕ζ 提交于 2019-12-01 07:35:50

TL;DR: Known dash problem; gray area, might be fixed; better not rely on exports surviving a non-bash parent.

This is caused by a change in dash 0.5.8; cp. dash removes exported bash functions from the environment.

There is no consensus yet whether this will be fixed. POSIX seems to allow the stripping of invalid environment entries, other (more obscure) shells apparently do this as well, but it causes problems in various applications, especially because /bin/sh is symlinked to dash (and therefore the default shell) in Ubuntu.


My personal use case is some short utility functions that I've put in my ~/.profile, and which I reference in some shell scripts. One of those runs in an autostarted Conky daemon, and that one misses the functions because the autostart happens through dash. I can work around this. The FPATH autoload mechanism from Korn shell would be nice to have in Bash, too...

This is not ideal, but you can define your functions inside of Dash:

$ foo() { echo "foobar"; }
$ dash -c "$(declare -f); foo"
foobar
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!