Loading

脚本中使用source ~/.bashrc失效问题

问题

使用脚本自动化,向~/.bashrc新增$PATH路径后无法通过source生效。

原因

~/.bashrc被设计成非交互模式下不生效

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

解决

通过手动export PATH=$PATH:$HOME/.local/bin的方式在脚本中临时更新。
开启新终端后.bashrc中添加的内容自动生效。

posted @ 2022-09-30 17:27  azureology  阅读(1958)  评论(0)    收藏  举报