Unreachable command in a shell script code while installing Oh My Zsh

Here is my sample1.sh:

#!/bin/bash

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo "foo"

Output:

enter image description here

Here is my sample2.sh:

#!/bin/bash

rm -rf ~/.oh-my-zsh
rm ~/.zshrc

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo "foo"

Output:

enter image description here

As you see, the only difference between above snippets are below lines:

rm -rf ~/.oh-my-zsh
rm ~/.zshrc

Question: why am I able to see foo, only when OMZ is already installed? What's so specific inside https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh, that after it detects that OMZ does not exist and can be installed, after successful installation, it doesn't continue to reach my foo?

Obviously, that echo "foo" was just an example to highlight the general problem.

In the final built of the script, what I want to achieve is to simply enable some plugins once OMZ is installed by calling:

sed -i '' -e 's/^plugins=.*/plugins=(git, sublime)/' ~/.zshrc

This line works fine only when I trigger it manually. The problem is that it never calls sed once OMZ is installed. Thanks for pointing out, where is the problem that I don't understand.


Solution 1:

Part of the install script for OMZ is to switch the current shell to sh with the line env zsh. I believe that this is basically causing your script to fork ZSH and never actually finish running. If you exit from the ZSH shell then it should continue as normal.