加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 01:28:46 所属栏目:Linux 来源:网络整理
导读:我需要一个在/ bin / sh启动时运行的脚本,类似于/ bin / bash的.bashrc.有没有办法做到这一点? 编辑: 我尝试了/ etc / profile和?/ .profile,我在两个文件中写了echo’hello world’.这些都不起作用.当我在控制台中输入sh时,没有任何东西弹出. 我正在使用A
我需要一个在/ 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读