4
1
I've been having an issue with getting my .profile to be sourced when SSHing into an Ubuntu 12.04 server instance. My .bashrc does the following towards the end:
if [[ "$TERM" != "screen-256color" ]]
then
tmux attach-session -t "$USER" || tmux new-session -s "$USER"
exit
fi
If I comment out that code block and log in with ssh again, the ~/.profile file is sourced as expected. There is no .bash_profile or .bash_login under ~ which would prevent ~/.profile from being read. Renaming .profile to .bash_profile as an experiment also didn't get the file sourced.
Does anybody have a guess for why that might be happening? I could just stuff everything into .bashrc, but I'd love to find out why .profile isn't being sourced.
Are you sure it is not sourced? What happens if you add an
echo foo > logfile
or similar just to check whether it is sourced? I am thinking that the problem may be the (as far as I can tell, useless)exit
in your snippet above. – terdon – 2013-07-01T18:21:55.260terdon, without the
exit
you'd have to type exit (or use CTRL-D) twice two log out of an ssh session. With exit, the bash session closes immediately, meaning that when tmux is closed, the ssh connection is closed as well.Testing with the snipped you shared above confirmed that .profile is indeed not read by the tmux session (but it's actually sourced in the bash session that starts tmux) – glitch – 2013-07-01T18:30:47.933
1
Ah, OK, sorry, I don't use
– terdon – 2013-07-01T18:35:49.713tmux
so I have not encountered that. So you are saying that adding theif
statement you have posted stops the file from getting sourced? Very strange... If you get no good answers here after a few days, you might want to flag the question for migration to U&L, you might have better luck there.Good suggestion, thank you. I'll let this sit here for a bit and move it if nothing happens. – glitch – 2013-07-01T18:44:31.783
2
I guess the shell running under
– Scott – 2013-07-02T01:00:34.490tmux
is not a login shell (what happens if you typelogout
?), so that shell will not look at.bash_profile
; it will look only at.bashrc
. So move the commands that you want executed from.bash_profile
to.bashrc
, or put them both places, or make one source the other. See Why ~/.bash_profile is not getting sourced when opening a terminal? on Ask Ubuntu.@Scott, you're correct, it's indeed not a login shell. All of your solutions seem valid. – glitch – 2013-07-02T03:12:39.760