Home » Questions » Computers [ Ask a new question ]

Is there a way I can use $PATH as defined by my bash profile?

Is there a way I can use $PATH as defined by my bash profile?

I spend most of my day ssh'd into servers. I have a series of aliases/functions/scripts that allow me to type p hostname from the terminal and execute GNU screen(1) on the remote side, using the following command:

Asked by: Guest | Views: 23
Total answers/comments: 2
Guest [Entry]

"If you can change the command your aliases use, you can have the remote side create an “interactive”, “login” instance of bash (i.e. one that uses your .bashrc and .bash_profile) to run screen:

ssh server -t 'exec bash -ilc ""exec screen -RD""'

If, in addition, you are not getting your normal environment (PATH, shell settings, etc.) in the shells created inside screen, you might need to tell screen to create “login” shells. Put shell -bash in your .screenrc on the remote ends, or add -s -bash to your screen invocation:

ssh server -t 'exec bash -ilc ""exec screen -RDs -bash""'

This will certainly run your .bash_profile twice (once before screen, once for each shell created inside screen). Depending on how you do your PATH manipulations, this may lead to multiple copies of the same additions to your PATH (this is generally not a problem)."
Guest [Entry]

.bashrc and .bash_profile are only processed for interactive shells, which any shell that executes a program such as screen (or echo in the test cases) is not. Read up in the bash man page about the BASH_ENV environment variable, which can be set up to run a start script for noninteractive shells.