Table of contents
We aim to use our custom bash scripts like other commands in the system just by typing their names.
To do so, we need to allocate a folder, write some scripts inside of that folder, and add this folder to the environment variable called
Let's go step by step through this process with more explanations.
Creating basic bash scripts
We need to write a few bash scripts to have something that we can add to the system.
Let's create a new folder with name
mkdir bin
Inside that folder, let's add two scripts.
bin/hello:
#!/bin/bash
echo "hello $1"
bin/bye:
#!/bin/bash
echo "bye $1"
Making script executable
The scripts have to be executable. To set the execute permissions on our scripts, we need to run this command:
chmod +x *
Adding custom scripts directory to $PATH variable
Now we need to make them visible for the system.
We can achieve this by adding our
You can check what is inside by typing in the terminal:
echo $PATH
Lastly, open your
export PATH=~/bin:"${PATH}"
Note: If you're using zsh, you can put this line to
Testing
Restart you terminal, and run any of your commands:
hello John
This will print
As an alternative option to restart, you can source your
source ~/.bashrc
or
source ~/.zshrc
Next time you start your terminal, your custom bash scripts will be in place so you can use them.