I am looking for a way to customize Ash sessions with my own sets of aliases and whatnots. What is the Ash equivalent of Bash's bashrc files?
3 Answers
Ash first reads the following files (if they exist):
- System:
/etc/profile - User:
~/.profile
-
15Provided that it is run as the login shell, which isn't the default (e.g. in Alpine Linux / Docker)Jakub Holý– Jakub Holý2017-02-01 10:29:53 +00:00Commented Feb 1, 2017 at 10:29
-
3@JakubHolý did you find a way to run profile script for non-login shell?David Lukac– David Lukac2017-11-28 13:20:51 +00:00Commented Nov 28, 2017 at 13:20
-
1@DavidLukac - See my other Answer here for non-login shells.spechter– spechter2018-01-22 00:21:21 +00:00Commented Jan 22, 2018 at 0:21
-
What do you mean by "first" reads these files? Will it do something else afterwards?HelloGoodbye– HelloGoodbye2020-02-16 02:47:24 +00:00Commented Feb 16, 2020 at 2:47
-
2Those are equivalent of .profile, the question is about .bashrc.Scorpion– Scorpion2022-11-29 20:51:18 +00:00Commented Nov 29, 2022 at 20:51
A non-login 'ash' or 'dash'-based shell may also 'source' a file if that file's full path is contained in the environment variable ENV (or perhaps SHINIT).
So if you set that somehow (Maybe in your ~/.profile, or some other 'overarching' environment control), then any future forked shells will run that script. Very handy for non-login cases.
Example: In your .profile, something like:
ENV=$HOME/.ashrc; export ENV
. $ENV
Or if you like being explicit:
ENV=/home/kwest/.ashrc; export ENV
# File in 'ENV' will be sourced for future shells. Also source it for this login shell:
. $ENV
Note that you should set ENV to a full explicit path, as the above will do. Don't use '~'.
It's hard to find explicit documentation on this for ash/dash, but it is confirmed to work on busybox-w32 (running on Windows). In fact it's hard to find good documentation on the featureset of ash at all.
UPDATE: There are a range of ash variants in the wild. 'ENV' may not work with all of them. There is some info on variants here: https://www.in-ulm.de/~mascheck/various/ash/
There is a suggestion in there that some ash variants may use 'SHINIT' in place of ENV.
-
3Not working for me under Alpine 3.7.knite– knite2018-06-14 22:50:27 +00:00Commented Jun 14, 2018 at 22:50
-
2@knite Busybox's Ash (used by Alpine) uses ENV.kirbyfan64sos– kirbyfan64sos2018-11-26 00:34:21 +00:00Commented Nov 26, 2018 at 0:34
-
1Has the ENV or SHINIT variable just to be set or to be set to a specific value? I am trying to force docker to read .profile in /root/.profile without explicitly starting with /bin/sh -lLeon– Leon2019-04-17 21:12:45 +00:00Commented Apr 17, 2019 at 21:12
-
@Leon - ENV (or maybe SHINIT) needs to contain the full path of the file to load/source. But this is only for startup of ‘ash’ shell variants - not the common sh or bash shells.spechter– spechter2019-04-19 05:44:36 +00:00Commented Apr 19, 2019 at 5:44
-
Can you provide an example of what should be set in
ENV?Saeed Neamati– Saeed Neamati2021-07-05 12:16:03 +00:00Commented Jul 5, 2021 at 12:16
Some year after the question on alipline 3.17 I figured out a solution (may not be the best, any comment welcome).
- Edit as root
/etc/profileto add at the end just before theunset scriptthis line:. $HOME/.profile - Then create a
.profilein your home dir as described before like this:ENV=$HOME/.ashrc; export ENV . $ENV
Then you can create a .ashrc in your home dir to set you aliases or other stuff.
-
I would recommend this to avoid the file missing error if the user doesn't create the file .ashrc .... export ENV=$HOME/.ashrc ; [[ -f $ENV ]] && source $ENVJoshua Briefman– Joshua Briefman2024-06-15 08:03:14 +00:00Commented Jun 15, 2024 at 8:03