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
You can write a bash script and save it in your
/usr/bin/ directory or any other directory. for example:
Create a new file and name it
mycommand.sh. then write the below code in it.
Set an executable access to this file by running this command in the terminal.
> chmod +x mycommand.sh
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.
Run the command
mycommand in your terminal and you will see the "Hello" string in the terminal.
You can write more complex scripts in that file and create your own commands.