Posts

Showing posts from August, 2015

Basic Bash Scripting - How to get started with bash

Image
1. Hello World Bash Shell Script First you need to find out where is your bash interpreter located. Enter the following into your command line: $ which bash Open up you favorite text editor and a create file called hello_world.sh. Insert the following lines to a file: NOTE:Every bash shell script in this tutorial starts with shebang:"#!" which is not read as a comment. First line is also a place where you put your interpreter which is in this case: /bin/bash. Here is our first bash shell script example: #!/bin/bash # declare STRING variable STRING="Hello World" #print variable on a screen echo $STRING Navigate to a directory where your hello_world.sh is located and make the file executable: $ chmod +x hello_world.sh Now you are ready to execute your first bash script: ./hello_world.sh 2. Simple Backup bash shell script #!/bin/bash tar -czf myhome_directory.tar.gz /home/linuxconfig 3. Variables In this example we declare simple bash va