[Shellscript] How to update Zsh from a shellscript?

Hi, I am using Zsh and am trying to update Zsh through a shellscript.

This is how it looks :

# Update OS
sudo apt update -y
apt list --upgradable
sudo apt upgrade -y
sudo apt autoremove -y
sudo apt autoclean

# Update Zsh
omz update

However, this does not update Zsh as it throws an error saying :
./update.sh: 7: omz: not found.

which omz showed :
image

Zsh version : zsh 5.8 (x86_64-ubuntu-linux-gnu)
OS : Ubuntu 20.04

Is it the same shell session? If you get rid of that last line, then run the script, then open a new terminal session, does running that command work?

Because if everything has been updated, and it’s still the same session, normal way of things is to do the updates, then start a new terminal session clean. And you can’t really do that within a single script (ie get the script to reload itself).

I don’t have time to test this, but sourcing the zshrc in the script before running update I don’t think will work in this case, but is worth a go. You could also try exec zsh before the update (which will replace the current shell process) but I think that will definitely break the script