Buy best selling Linux books

<< View More Computer Tips

Added On: 18/12/15   |    Category: Ubuntu    |    Number of Views: 1466

Create a simple bash script in Ubuntu   

Note: This tutorial will also work in Kubuntu, Lubuntu, Xubuntu, Ubuntu Gnome, Ubuntu Mate, Linux Mint and other Ubuntu Based Distributions.

Bash scripts allow to automate tasks in Ubuntu. A good example of using a bash script could be to install a bunch of packages after reinstalling Ubuntu.

To create your first bash script in Ubuntu follow the instructions below.

We first need to identify the path to bash, so open your terminal and enter the following command

which bash

It will return with /bin/bash, this is what you will enter at the top of every new bash script you create.

Open a new text document and copy and paste the code below.
echo "My First Bash Script"

Save the text document as to your desktop so you can easily locate it.

Before we can run the bash script we need to make it executable.Open you terminal and change directory to your desktop using the following command
cd /home/{username}/Desktop

Remeber to replace {username} with your Ubuntu username

Make the file executable my issuing the following command. What this command does is give you read and write permissions on the file.
chmod +x

The next part is to run the bash script. In the terminal enter the following command

Search Site

Search other tutorials and tips on My Computer Tips by entering your search terms below


The Linux Foundation

Best selling Unix / Linux books
Nvidia Graphics Cards
Save 15% off .CO.UK domains at 123-Reg
Save 15% off .COM domains at 123-Reg
cPanel Hosting Plans
Xilo Web Hosting Plans