I have a Bash script that needs to be run from an interactive prompt, due to environment variables and configuration that only seems to be read when actually logged into a session. Examples below:
Good
me@client:~$ ssh box
user@box:~$ /usr/local/bin/myscript
Bad
me@client:~$ ssh box "/usr/local/bin/myscript"
Is there any Bash-fu that I can use in my script to determine if it's being run via a one-line SSH command?
~/.profile
etc. to be read. – muru Feb 04 '16 at 14:19. ~/.profile
to the script, but that could cause other problems. For example, what if~/.profile
sources.bashrc
and.bashrc
sources a third file that sets up the environment? In that case, assuming the.bashrc
is exiting on non-interactive shells, the same problem would occur. It's probably worth posting an answer suggesting the OP source whatever files are necessary but I felt this was both cleaner and actually answers the question asked. – terdon Feb 04 '16 at 14:22