As part of my quest to preserve bashrc and vimrc when switching to non-root users, I plan on making some super ugly aliases to switch to other users, immediately execute some commands, and then drop me at their prompt.
Run an interactive bash subshell with initial commands without returning to the (“super”) shell immediately does not appear to answer my question.
bash --init-file <(echo "ls; pwd; a=7") works as expected; but
sudo bash --init-file <(echo "ls; pwd; a=7") does not (
echo $a returns nothing; nothing is printed to the terminal from
Why does the first command work, but not the second? How can I make a bash command that executes commands in other user's shell which persistently change environment variables and then access that shell? Note that this is more about making this work for switching to other non-root users; I already have a different solution that works for root.