linux – / bin / sh有.bashrc的替代方案吗?

我需要一个在/ bin / sh启动时运行的脚本,类似于/ bin / bash的.bashrc.有没有办法做到这一点?

编辑:

我尝试了/ etc / profile和〜/ .profile,我在两个文件中写了echo’hello world’.这些都不起作用.当我在控制台中输入sh时,没有任何东西弹出.

我正在使用ArchLinux.

最佳答案
在Arch中,/ bin / sh是/ bin / bash的符号链接,它有很多关于启动脚本的规则,在调用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, …

如果从控制台启动它,没有任何命令,即作为交互式非登录shell,则应使用ENV变量:

export ENV=~/.profile
sh

要么

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.

或者,您可以使用–login选项使其行为类似于登录shell,并读取.profile文件.

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

转载注明原文:linux – / bin / sh有.bashrc的替代方案吗? - 代码日志