Bash Scripting

less than 1 minute read

Bash is a powerful Linux terminal application and bash scripting can be used to automate repetitive tasks easily. In this post, we will look at some basic bash scripting.

Create a script file


Enter the following into that file

echo “Hello world…”
sleep 1
echo “How are you?”
read ans
echo “you typed $ans

Make the script executable

chmod +x

Execute the script


How to run a bash script from anywhere

Create a directory say “bin” under your home directory and update your path variable to include this bin directory.
Include the following in .profile or .bash_profle file to make it permanent.

export PATH=$PATH":$HOME/bin"

Or use the following if you want the directory to precedent system directories


create a script say, “hello” and keep it in your bin directory and give execute permission to the hello script.

echo My first program

From any directory, you simply type:


You will get the following output

My first program