Skip to main content

Change directory of remote machine through ssh after ~./bashrc execution [Resolved]

I am trying to run a script on a remote machine via ssh. For this I want to change the directory and run the script from there. I found that the standard method on how to do this is:

ssh -Y -t user@server 'cd dir; exec bash'

However, the problem is that prior to running my script I need to setup some further scipts which I do in my ~./bashrc. My problem is that the way the command is written the change of directory happens before the ~./bashrc is even executed, i.e. messing up the code I need to set up before. Note: changing the command to

ssh -Y -t user@server 'exec bash; cd dir'

executes the bash normally, but doesn't change the directory afterwards. Thanks in advance.


Question Credit: Mark
Question Reference
Asked July 21, 2019
Posted Under: Unix Linux
20 views
2 Answers

What about a here document, something like below:

ssh user@server << EOF exec bash       
cd dir
EOF

credit: alpha
Answered July 21, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA