Add Function to ~/. Zshrc

I'm trying to apply the following :

But I'm stuck/missdo on the part to copy and paste the function cppcompile when I open

sudo code ~/.zshrc

Because after following all the steps when I try to compile my program I got the following :

bash: cppcompile: command not found

So how to add a function to ~/.zshrc? (Personally, I just copy and paste it as it said, or maybe there is a proper way to do it?

1 Answer

.zshrc is executed when you open a new shell. Changes in it don't affect existing shells automatically. So either:

  • Open a new shell, or
  • Use the command . ~/.zshrc (yes, it starts with a dot followed by a space) to execute the file again in your current shell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest