Bash Scripting
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
vim temp.sh
Enter the following into that file
#!/bin/bash
echo “Hello world…”
sleep 1
echo “How are you?”
read ans
echo “you typed $ans”
Make the script executable
chmod +x temp.sh
Execute the script
./temp.sh
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
PATH=$HOME/bin:$PATH;
create a script say, “hello” and keep it in your bin directory and give execute permission to the hello script.
#!/bin/bash
echo My first program
From any directory, you simply type:
hello
You will get the following output
My first program
Comments