Ash profile/configuration file

28,127

Solution 1

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

  • System: /etc/profile
  • User: ~/.profile

Solution 2

A non-login 'ash' or 'dash'-based shell may also read a file if specified 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/.shinit; export ENV
. $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.

Share:
28,127

Related videos on Youtube

reg
Author by

reg

Updated on September 18, 2022

Comments

  • reg
    reg almost 2 years

    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?

  • Jakub Holý
    Jakub Holý over 7 years
    Provided that it is run as the login shell, which isn't the default (e.g. in Alpine Linux / Docker)
  • David Lukac
    David Lukac over 6 years
    @JakubHolý did you find a way to run profile script for non-login shell?
  • spechter
    spechter over 6 years
    @DavidLukac - See my other Answer here for non-login shells.
  • knite
    knite about 6 years
    Not working for me under Alpine 3.7.
  • kirbyfan64sos
    kirbyfan64sos over 5 years
    @knite Busybox's Ash (used by Alpine) uses ENV.
  • Leon
    Leon about 5 years
    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
  • spechter
    spechter about 5 years
    @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.
  • HelloGoodbye
    HelloGoodbye over 4 years
    What do you mean by "first" reads these files? Will it do something else afterwards?
  • Saeed Neamati
    Saeed Neamati almost 3 years
    Can you provide an example of what should be set in ENV?
  • spechter
    spechter almost 3 years
    @SaeedNeamati - Added in post.