karlosss karlosss - 1 year ago 95
Bash Question

Is there an alternative for .bashrc for /bin/sh?

I need a script which is run on startup of

, similar to
. Is there any way to do this?


I tried both
, I wrote
echo 'hello world'
to both files. None of these are working. When I type
into the console, nothing pops up.

I am using ArchLinux.

bwt bwt
Answer Source

In Arch, /bin/sh is a symlink to /bin/bash, which has quite a few rules about startup scripts, with special cases when called sh :

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, ...

If you start it from the console, without any command, i.e. as an interactive, non-login shell, you should use the ENV variable :

export ENV=~/.profile


ENV=~/.profile sh 

When invoked as an interactive [non login] shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute.

Alternatively you can use the --login option to make it behave like a login shell, and read the .profile file.

sh --login

When invoked as an interactive login shell [with the name sh], or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download