我使用shell脚本用于某些特定目的,并且它具有以下功能.bash_profile:
function refresh {
source "$HOME/.bash_profile"
}
Run Code Online (Sandbox Code Playgroud)
这同样.bash_profile有这样的说法:
if [ -f "$HOME/.bash_prompt" ]; then
source "$HOME/.bash_prompt"
fi
Run Code Online (Sandbox Code Playgroud)
哪个也应该重装.bash_prompt; 并且确实如此,该提示文件包含的值应该更改提示的显示(颜色,文本放置等),但这些值不会更改.它们只在新的终端窗口上更改,或者我source "$HOME/.bash_prompt"在终端窗口内显式调用.
我在这里做错了吗?
这是我的.bash_prompt来源:
# Colors
# Bunch of color codes
function print_before_the_prompt {
# create a $fill of all screen width
let fillsize=${COLUMNS}
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
printf "$txtrst$bakwht%s" "$fill"
printf "\n$bldblk%s%s\n" "${PWD/$HOME/~}" "$(__git_ps1 "$txtrst [$txtblu%s$txtrst]")"
}
# Load Git completion and prompt
if [ -f "/usr/local/opt/git/etc/bash_completion.d/git-completion.bash" ]; then
source "/usr/local/opt/git/etc/bash_completion.d/git-completion.bash"
fi
if [ -f "/usr/local/opt/git/etc/bash_completion.d/git-prompt.sh" ]; then
source "/usr/local/opt/git/etc/bash_completion.d/git-prompt.sh"
fi
GIT_PS1_SHOWDIRTYSTATE=true
PROMPT_COMMAND=print_before_the_prompt
PS1="\[$txtred\]?\[$txtrst\] "
Run Code Online (Sandbox Code Playgroud)
您还需要获取托管该refresh函数的脚本,而不是执行它.如果不这样做,则仅在执行脚本期间更改环境.
说明:当您执行脚本时,它会继承其父级的当前环境(在本例中为:您的shell),并且它具有自己的环境.脚本中的所有环境更改仅适用于脚本本身及其子项.
但是,在获取脚本时,所有更改和命令都会直接影响父项的环境.
通常,建议将要使用的脚本与通用脚本分开.例如,您可以拥有一个dev.sh包含特殊开发项目的特殊环境变量的文件,这些变量需要一些特殊变量.
如果您想快速.bash_profile获取当前shell的源代码,可以设置别名.通过执行脚本来完成它是不可能的.
| 归档时间: |
|
| 查看次数: |
1137 次 |
| 最近记录: |