Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Load your bash profile even when switching user

If you use a shared application account, for example, ansible , and want your profile to be used even after switching to that user, here is a solution for you. Add this to the destination user ~/.bashrc.

echo "${SSH_CLIENT}" | grep -q '192.168.2.88' && __bp=1
test "$( stat -c '%U' "$( tty 2>/dev/null )" 2>/dev/null )" = "bgstack15" && __bp=1
test "${__bp}" = "1" && test -f /usr/bin/bp && . /usr/bin/bp --noclear

I am using a world-readable copy of my bgstack15 profile, aka bash profile.

Comments