我怎么能告诉(在〜/ .bashrc中)我是以交互模式运行,还是说,通过ssh执行命令.我想避免在.bashrc中打印ANSI转义序列,如果它是后者的话.
根据男子打击:
PS1 is set and $- includes i if bash is interactive,allowing
a shell script or a startup file to test this state.
所以你可以使用:
if [[ $- == *i* ]] then do_interactive_stuff fi
也:
When an interactive shell that is not a login shell is started,bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc,if
these files exist.
所以〜/ .bashrc仅用于交互式shell.有时,人们从〜/ .bash_profile或〜/ .profile中获取它,这是不正确的,因为它会干扰预期的行为.如果要简化常见代码的维护,则应使用单独的文件来包含公共代码,并从两个rc文件中独立地获取它.
最好是从登录rc文件(例如〜/ .bash_profile或〜/ .profile)没有输出到stdout,因为它可能会干扰rsync的正常操作.
在任何情况下,测试交互性仍然是一个好主意,因为可能存在不正确的配置.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。