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.
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.
a -- alert
b -- backspace
n -- newline
r -- return
t -- tab
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.
$ 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