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?


Invoke $SHELL instead.

ssh -t user@server 'cd /home/some/dir ; exec "$SHELL"'

You can do this like so...

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

Where bash is your desired shell.

  • 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
  • 1
    @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
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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