Basic Linux Shell Scripting Concepts


By Corey Hynes, September 5th, 2002 Posted in Linux. Subscribe to our RSS Feed



Rather Have Fast and Secure Remote Control?

 Securely access PCs and servers worldwide through any firewall. Try it and see for yourself!

Select Statements

This is used to present the use with a simple menu of choices. Consider the following example.

#!/bin/sh
echo "What is your favourite OS?"
select var in "Linux” “Gnu Hurd” “Free BSD” “Other”; do
break
done
echo “You have selected $var”

For Loops

These loops are used when you have a list of values you want to test. Consider the following example.

#!/bin/bash
for myvar in a b c; do
echo $myvar
done

Quoting

Finally we will cover the idea of quoting. This can be confusing when you first deal with it. Quoting takes the value that is contained within the quotes and treats it as a literal value. For example, ‘$var’ will print $var, as opposed to the value of $var. Both single and double quotes can be used to represent literals, with the difference being that a single quote is an absolute literal, while a double quote will display the value of a variable, if it is inside the quote.

That should be enough to get you started. The next article in this series will further address scripting by taking a look and some commands that are commonly used in scripts such as GREP, as well as the concept of input and output redirection. Finally, my third article will tie things together to create usable administrative scripts.

Written by Corey Hynes - Visit Website

Go To Page: 1 2 3 4 5



Print This Post Print This Post













All Tutorials by Category:















Entire site Copyright © 1999-2007 2000Trainers.com, all rights reserved.
Content on this site may not be copied or reproduced in any way without permission.





IT Showcase


Text Link Ads

View all Tutorials by Category: