k den wrote:Hey guys,
I've been trying to run some code automatically at the beginning of every terminal session using the file ~/.bash_profile, but for some reason the code only runs when I access the terminal interactively (in other words, through SSH.)
You are saying that it only runs when you do something that requires you to login? If you look at the ~/.profile file, you will likely see that it says that it doesn't run if .bash_profile exists but that it is also only going to run if it is a login shell.
When I put
echo "This is a login shell"
in the .profile file, it echoes that text when I ssh in but it doesn't when I just su user into that account. Then I added to the .bashrc file the following and tested again:
echo "We are now in .bashrc"
When I did the su, I *only* got the part about being in .bashrc but when I ssh, I get *both* strings. You'll want to experiment with all this because apparently it isn't perfectly consistent under every unix like operating system and you can source different files to make it behave however. Including an echo line saying what file is being shown might be useful in repeatedly giving you clues as to which is going to run when you do which type of account use.