So I've found that running ssh remote "<command>"
runs the remote shell in non-interactive mode, thus it doesn't source the same startup scripts as if it were an interactive shell. My issue is that I need to source these startup scripts when running a remote command, but I don't actually need an interactive shell, just the startup scripts. Is there anyway I can force the non-interactive shell to source the same startup scripts for an interactive shell?
Asked
Active
Viewed 323 times
1

mtveezy
- 661
- 3
- 10
- 21
-
how would this work? the scripts are on your local machine and you want to source them in the remote shell? – Mircea Mar 02 '16 at 19:13
-
Sorry for the confusion, I want it to source the scripts on the remote machine, in the remote shell – mtveezy Mar 03 '16 at 18:49
1 Answers
1
You could have your "command"
do the sourcing you want. For example, it could become ". .bashrc; command"
Or you could invoke your command with bash -i "..."
to tell bash to start in interactive mode even if it normally wouldn't have.
Or you could pass in the BASH_ENV
shell variable that points to the startup script that you want, since bash
will source that file when started in non-interactive mode.

Eric Renouf
- 13,950
- 3
- 45
- 67
-
could you elaborate on how to tell bash to start in interactive mode? I tried `ssh remote bash -i "bin/some_script.sh"` but it still doesn't work – mtveezy Mar 03 '16 at 18:56
-
Are you sure that the variables you want are in your `.bashrc` then? Your example works with a dummy script for me, though it won't do aliases if that's what you're trying to use. Then you might want to look at http://stackoverflow.com/questions/1615877/why-aliases-in-a-non-interactive-bash-shell-do-not-work – Eric Renouf Mar 03 '16 at 19:08
-
I suspect it's `-t` you were thinking about rather than `-i`. `-i` is to specify an identity file. `-t` is to force a pseudo terminal. – Matthew Walker Jul 18 '22 at 05:49
-
1@MatthewWalker the `-i` there is an argument to `bash` not to `ssh` , it's intended as part of the command being executed remotely here. – Eric Renouf Jul 18 '22 at 17:17