The title pretty much says it all (but maybe there's something more sinister in play.) I'm aware of /etc/profile.d/*.sh
scripts that run when you login but that doesn't seem to work as expected when you simply start a shell. Here's an example with docker:
Create a small script :
$ echo "echo hello world" > startup.sh
Run the alpine shell with the script mounted like so:
$ docker run -it --rm -v `pwd`/startup.sh:/etc/profile.d/statup.sh alpine sh
All you'll get is a shell prompt:
/ #
It does print "hello world" when you su -
from here though:
/ # su -
hello world
2bf679a5677d:~#
But a simple sh
to start a shell will not do:
/ # sh
/ #
So, what's the issue here? Is it an obscure Alpine Linux thing? Is it an obscure Alpine Linux Docker image thing?
As man ash
tells you in the Invocation section, the environment variable ENV
can be used to specify a file to source during shell startup.
In your Dockerfile:
ENV ENV=/home/youruser/.rc
...and then your shell will execute the contents of /home/youruser/.rc
during startup.
In bash, BASH_ENV
(used when not in POSIX mode) runs even for noninteractive shells; when bash is in POSIX mode, it runs ENV
for interactive shells only (which is the only circumstance in which the POSIX specification requires ENV
to be honored).