how to create a bash script in ubuntu

Create a Script

Bash is a scripting language. Here we are deep diving to create a Bash Script in Ubuntu.

I am using nano editor here to create script file you can choose what ever you want

sudo nano

Below is a sample code for ‘Hello World’ bash script. We are going to save this script with .sh extension (/path/to/hello_world.sh) but it is not necessary.

#!/bin/bash
echo Hello World

The first line of the script just defines which interpreter to use.

Give Permission

To run the bash script we need to give execute permission to our file. We do this with chmod command as below:

chmod a+x /path/to/hello_world.sh

Run Bash Script

bash hello_world.sh

References

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Leave a Reply

Your email address will not be published. Required fields are marked *