Category: Ubuntu

Added: 18th of December 2015

Viewed: 2039 times

Create a simple bash script in Ubuntu

This tutorial works in Ubunbu, Kubuntu, Xubuntu, Lubuntu, Ubuntu Mate and other Ubuntu based distributions. The tutorial also works in Linux Mint and other Debian 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.
#!/bin/bash
echo "My First Bash Script"

Save the text document as my_first_bash_script.sh 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 my_first_bash_script.sh

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

Other Tips & Tutorials

Ubuntu

Download Microsoft Edge preview version for Ubuntu and Ubuntu based distributions

Posted: 22nd of October 2020

Views: 27

Ubuntu

Create a really simple banner using GIMP (GNU Image Manipulation Program) in Linux

Posted: 7th of August 2020

Views: 157

Ubuntu

Install the tree package to list folders and files in a tree like format inside the terminal on Linux

Posted: 22nd of July 2020

Views: 154

Ubuntu

Ubuntu 4.10, Warty Warthog. The first Ubuntu Linux Distribution

Posted: 6th of October 2019

Views: 953

Ubuntu

Sim City 4 Deluxe Edition Install Wine Linux. Trouble installing from CD/Disk 2

Posted: 19th of May 2019

Views: 1216

Ubuntu

Where are the fonts located in Ubuntu and other Ubuntu based distributions

Posted: 3rd of June 2018

Views: 1329

Ubuntu

Install MariaDB Database in Ubuntu and other Ubuntu based distributions (Part 1)

Posted: 26th of May 2018

Views: 1264

Ubuntu

Convert .mkv video to .png images using ffmpeg

Posted: 24th of May 2018

Views: 2598

Ubuntu

Shutdown Ubuntu using the terminal

Posted: 20th of May 2018

Views: 1137

Ubuntu

Running Sketchup 8 in Wine. Sketchup was unable to initialize OpenGL, Linux

Posted: 29th of May 2016

Views: 3559