A Bash script always start with the identifier:
#!/bin/bash
This goes before any other lines at the top of every Bash script. Let's make the world famous “Hello World” script. The purpose of this script is to write “Hello World” to the Terminal.
Open a file with a text editor in Terminal; we do that like this:
nano hello
If the text file doesn't exist then it will be created. To get Linux to recognize it as a Bash script put #!/bin/bash at the top of this file.
On the next line write echo “Hello World”. Close the file by hitting ctrl->x y and enter. In order to be able to run the script, we first need to make it executable.
chmod +x hello
Now run the file:
./hello
This will write “Hello World”, without quotations, to the screen.
Congratulations; you've now written your first Bash script.