50

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?

reg
  • 1,113
  • 1
  • 8
  • 12

3 Answers3

47

Ash first reads the following files (if they exist):

  • System: /etc/profile
  • User: ~/.profile
reg
  • 1,113
  • 1
  • 8
  • 12
17

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.

spechter
  • 271
  • 2
  • 4
  • 3
    Not working for me under Alpine 3.7. – knite Jun 14 '18 at 22:50
  • 2
    @knite Busybox's Ash (used by Alpine) uses [ENV](https://git.busybox.net/busybox/tree/shell/ash.c?h=1_29_3#n14189). – kirbyfan64sos Nov 26 '18 at 00:34
  • 1
    Has 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 -l – Leon Apr 17 '19 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 Apr 19 '19 at 05:44
  • Can you provide an example of what should be set in `ENV`? – Saeed Neamati Jul 05 '21 at 12:16
  • @SaeedNeamati - Added in post. – spechter Jul 18 '21 at 03:01
0

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/profile to add at the end just before the unset script this line:
    . $HOME/.profile
    
  • Then create a .profile in 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.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
phane
  • 1