How can I get ash to load some environment variables on startup?
Just put them in /etc/profile
/etc/profile is only read for login shells; what about non-login shells, as frequently pop up when working with docker (which uses alpine>busybox>ash)?
A non-login shell will read a file if specified in the environment variable ENV
Great, how can I ensure ENV is set? It is itself an environment variable, and blank by default.
Essentially I’m looking for some overarching config file which ash is guaranteed to read. Preference for the version of ash used by busybox (BusyBox v1.28.4, if you want to be exact). Does such a thing exist? And yes, I know about the ENV directive in docker, which could be used to set $ENV when building a docker image; I'd still like to know if this is possible outside docker.
As a side note, can anyone explain this odd behavior in alpine?
$docker run -it alpine / # echo $CHARSET #proof /etc/profile has not run / # echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin / # env -i sh -c 'echo $PATH' /sbin:/usr/sbin:/bin:/usr/bin / # echo $ENV / #
What’s adding to the PATH compared to the default PATH set for a new shell, when we can show /etc/profile hasn’t? It’s not docker dickery either, the Dockerfile for alpine is deliberately minimal:
FROM scratch ADD rootfs.tar.xz / #Automatically extracts, and I’m pretty sure that’s all CMD ["/bin/sh"]
I only mention this because it looks like someone has found a way to persist an environment variable in a non-login shell without the use of $ENV.
I appreciate any information or context, however tangential.