1

I am trying to connect to a server via ssh and then execute a command. So far so simple.

The twist is that on that server, I start zsh from my bash. So in my .bashrc I have the command:

exec /bin/zsh -l

So that when I login, it automatically starts my z-shell. And I want to keep it like that.

Unfortunately, when I run my bash script to connect to the server and run a command, it does not work. No error message, the command just runs endlessly.

Is there a way to do this in in spite of the shell change?

Thanks!

5
  • 2
    Why do you want to keep running zsh from bash? If you always use zsh it'd make more sense to run chsh to change your login shell.
    – Panki
    Feb 28, 2020 at 10:32
  • thanks for the tip, however, chsh does not work because we are using ldap and chsh.ldap returns a segmentation fault. I spend ours on trying to get that work lol
    – cmplx96
    Feb 28, 2020 at 11:04
  • 1
    All chsh really does (afaik) is edit /etc/passwd, so you might be able to get the same result with root and a text editor.
    – Panki
    Feb 28, 2020 at 11:48
  • we have a different config, none of the users are in /etc/passwd
    – cmplx96
    Feb 28, 2020 at 12:54
  • also, unfortunately, I don't have root rights
    – cmplx96
    Feb 28, 2020 at 12:58

1 Answer 1

1

I found a solution.

In the .bashrc, check whether or not the shell is in interactive mode. If yes, open z shell.

if [[ $- == *i* ]]
then
    exec /bin/zsh -l
fi

That way, if you execute a bash script that connects to the server and executes the command, z shell won't be started.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .