Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to ssh from one machine to another within a Python script (Nautilus script). It works with the following:

ssh -t user@server "cd /home/some/dir ; csh"

However I don't like the idea of hardcoding the shell type.

Is there a way to set cwd within the ssh command without the need to hardcode the shell type?

share|improve this question
Technically it was a python script ;-) – Johnsyweb May 30 '11 at 10:18

2 Answers 2

up vote 2 down vote accepted

Invoke $SHELL instead.

ssh -t user@server 'cd /home/some/dir ; exec "$SHELL"'
share|improve this answer
Thanks, worked like a charm! – umpirsky May 30 '11 at 13:39

You can do this like so...

ssh -t user@server "cd /home/some/dir ; bash"

Where bash is your desired shell.

share|improve this answer
Thanks, it works. Is there a way to auto-detect or ommit shell, so it go to default? I don't like the idea to hardcode it. – umpirsky May 30 '11 at 11:21
@umpiresky: I don't have an Ubuntu box on which to test this, but on *BSD I can do: ssh -t user@server "cd /home/some/dir ; login user" (where user is the username that you have provided to ssh). If your remote host has the same setup as localhost you could use ${SHELL} instead. YMMV. – Johnsyweb May 30 '11 at 11:30
@Johnsyweb Nope, login user ddn't work for me. I'm connecting from Ubuntu to FreeBSD, but it would be nice to work for any server. That's why I don't like the idea to hardcode shell type (csh in my case). – umpirsky May 30 '11 at 12:05
login user works for me on FreeBSD. – Johnsyweb May 30 '11 at 12:06
Hm, maybe, yes. But we already have a working nautilus script, lets just make it better. Thank fou your valuable help. – umpirsky May 30 '11 at 12:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.