我当前的用户,firstuser 有一个默认的 shell /bin/sh
我的.profile
是一行:
[ -f $HOME/.bash_profile ] && . $HOME/.bash_profile
我的 .bash_profile
是一行:
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
我的.bashrc
有如下代码:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
export PS1='$(__git_ps1) \$ '
问题是:
$ su seconduser
Password:
bash: __git_ps1: command not found
$
注意:
seconduser 的 shell 为 /bin/bash
我想要的是将来自 firstuser 的所有自定义设置带到 seconduser 的 shell 中。
最佳答案
您的代码将提示变量 PS1
按字面意思设置为 $(__git_ps1)\$
。你的 shell 在显示提示时解释它。
$(__git_ps1)
尝试将 __git_ps1
作为命令运行并获取其输出 - 这 command substitution .你确定你想要那样吗?在这种情况下,请确保它是一个有效的命令并且它在 PATH 中。
关于bash - __git_ps1 在使用 Bash su 用户名时找不到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52598282/