how to create custom zsh commands?

I want to make my own zsh commands on my mac. And I have no idea how to do that and how to write shell code. How do I get started? I want to make a basic command like this:

myname@My-MacBook-Air  ~ hi
hi, user!


  • You can write a bash script and save it in your /usr/bin/ directory or any other directory. for example:

    Step 1

    Create a new file and name it then write the below code in it.

    echo "Hello"

    Step 2

    Set an executable access to this file by running this command in the terminal.

    > chmod +x

    Step 3

    Make sure the /usr/bin/ directory is in your PATH by running this command in the terminal.

    > echo $PATH

    If there is not, visit this website to learn how to add a directory to the PATH.

    Step 4

    Run the command mycommand in your terminal and you will see the "Hello" string in the terminal.

    > mycommand

    You can write more complex scripts in that file and create your own commands.