Linux Tutorials
Building Hadoop Clusters On Linux In EC2
Installing And Using Hadoop
Setting Up SSH Keys Using SSH Agents And Tunnels
Creating OpenSSL Certificates and Certificate Authorities
Installing and configuring Xen
IPTables Primer
Linux Basic Bash Scripting

Linux Basic Bash Scripting

Basic Syntax

Shell scripting in linux is a very valuable tool. The bash shell is a powerful and flexible tool. In this tutorial we're going to cover basic syntax, variables, conditional statements, and loops. We're just going to jump right in with our first script.
#!/bin/bash
echo "Hello World"

This is the easiest script there is. The script starts as all linux scripts should with a shebang (#!) followed by the shell or application used to execute the script.

Linux interprets ' and " differently in shell scripting. The single quote (') interprets all text inside verbatim, while the double quote (") works like the single quote except it interprets escape characters. Double quotes are commonly used to group words seperated by spaces into one value.

The is used to escape the following character. One common use is to declare a quote to be interpreted as a character and not in the capacity discussed above. The is also used to create escape characters to perform functions such as new line and alarm bells.

LIST OF COMMON ESCAPE CHARACTERS

a -- alert
b -- backspace
n -- newline
r -- return
t -- tab

I/O Redirection

Linux allows you to do IO redirection via the | < > characters. The > character redirects the programs output via stdout to a file. The < will redirect a file into a program. If you want to redirect the output of one program into another use the | character.

Examples:
$ ls -l | grep filename -- Takes the output of ls -l and pipes it through grep.
$ ls -al > filename -- Takes output from ls -al and writes it to the file filename.
$mysql -u user < file.sql -- takes file.sql and directs it into mysql.
* $ is shell prompt not to be entered

 1 2 3 4 5  >> Variables
New Content