Issue
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?
Solution
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. This applies even to noninteractive, non-login shells.
In your Dockerfile:
ENV ENV=/home/youruser/.rc
...and then your shell will execute the contents of /home/youruser/.rc
during startup.
This is not specifically an ash
behavior or an Alpine behavior; it's true of all POSIX sh implementations. (bash uses BASH_ENV
instead except when running in sh compatibility mode, at which point it too honors ENV
).
Answered By - Charles Duffy Answer Checked By - Pedro (WPSolving Volunteer)